I’m due to transfer a load of content from several websites into one, all have different structures and content.
Once all the content is in there and the site is ready to go, I need to switch the old domains off - how do I redirect old url’s picked up in google to the current site, is it possible? and could I just link back to archived content using the ip address?
[FONT=Verdana]Assuming you’re on an Apache server, you can set up redirects in the .htaccess file. I’d advise against using a catch-all, except for pages that no longer exist or have no real equivalent on the new system. If somebody follows a link from a search engine, they want to be taken to the page with the information they’re looking for, not a generic landing page.
There are links to tutorials in the stickies for this forum which might help.[/FONT]
If running PHP on your server you can do it using this redirect class.
On the server with your old domains at the very top of the index.php (or whatever file you set as the default index), without outputting any content including spaces do:
$o_Redirect = new Redirect( 'http://www.mydomain.com'); //instantiate the object and set default redirect
$o_Redirect->setRedirect('www.mynewdomain.com');
$o_Redirect->go(); //issue the redirect to the new domain.
class Redirect {
protected $redirect;
protected $default_redirect;
function __construct($default_redirect = '') {
$this->default_redirect = $default_redirect;
}
public function setRedirect($redirect) {
$this->redirect = $redirect;
}
public function go() {
$this->redirect();
}
protected function redirect($moved_permanently = 0) {
if($moved_permanently != 0){
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
}
header('Location: '.$this->redirect);
exit();
}
public function getRedirector(array $urls = null){
$default_urls = array(
'http://www.google.ca'
,'http://ca.yahoo.com/'
,'http://www.bing.com/?cc=ca'
);
if($urls != null){
shuffle($urls);
return $urls[0];
} else {
shuffle($default_urls);
return $default_urls[0];
}
}
}
Any search engine bots will traverse to this redirect and will take note of the fact that the content is moved. They will then travel to your new site and start index it.
Also people that have the old links bookmarked will be redirected to the new site.
For this to work you still need to serve both old and new content and you can not change the DNS for the old site or the redirects will never be reached.
This technique gives you a lot of control as to exact paths you want to redirect to.
As soon as the old domain is ‘switched off’ there will be no way for any of the existing links or routes to that old domain to redirect.
Say I have your old domain and in my browser I try http://www.oldsite.co.uk/index.asp?page=1 the public DNS being cancelled for the www.oldsite.co.uk will mean that the DNS forwarder routers will soon forget to do this route and I will get a ‘Page not found’ error, not to be confused with a 404 error as there won’t be a site/server that I will route to, so I am out of luck.
The way this is normally done is that both domain are run for a period say 3 months. Then you set some mechanism for redirecting calls to the old site to the new one. There are a number of suggestions in this thread that you can try .htaccess or the php redirect would work. This process would work like this:
The public DNS routers point to your server and I connect to it
Upon connection, I am redirected using headers. I also use headers to tell search bots can be told that this is a permanent move. Overtime the google bots and other search bots will mark your old domain as permanently move.
You could use a little javascript to get the referrer and let them know to bookmark the new site as the old one is going away.
After a length of time the search bots will have updated the permanent move and continue indexing your new domain.
If you simply phase out your old domain then you can not do a redirect.
Thanks for that, really appreciate it. After re-reading your great post several times I was thinking along the lines of below…
Rather than switch them off - If I can change the DNS and get the old domains to point to a section on my new site (hopefully I should be able to do this), www.newsite.co.uk/oldsitesrea. I can get a splash page setup explaining the new site setup and a link to the old site that no longer has the domain for archive purposes.
All new visitors will then be sent to the new site (hopefully). Regarding the bookmarked and old google search results - as the old links to the old domain will now go to the new site. Is there a way I can redirect the old google links to the archive site? Something like…
The DNS directs them to the approriate www.newsite.co.uk/oldsitesrea, could I then somehow store the original old site link, and send them to the appropriate page on the archived site? As the querystring will be the same on the old site (index.asp?page=1), just the domain will of changed.
/* This is index.php on the old site */
<?
$o_Redirect = new Redirect();
switch($_GET['page']){
case 1:
$o_Redirect->setRedirect('http://www.newsite.co.uk/index.asp?page=1');
$moved_permanently = 1;
$o_Redirect->go($moved_permanently); case 2:
$o_Redirect->setRedirect('http://www.newsite.co.uk/index.asp?page=2');
$moved_permanently = 1;
$o_Redirect->go($moved_permanently); /*more case statements would go here. Each would match a page on your old site*/ default: $o_Redirect->setRedirect('http://www.newsite.co.uk/index.asp'); /* By default redirect them to the home page */ $moved_permanently = 1; $o_Redirect->go($moved_permanently);}
class Redirect { protected $redirect; protected $default_redirect; function __construct($default_redirect = '') { $this->default_redirect = $default_redirect; } public function setRedirect($redirect) { $this->redirect = $redirect; } public function go($moved_permanently = 0) {
$this->redirect($moved_permanently); } protected function redirect($moved_permanently = 0) { if($moved_permanently != 0){ // Permanent redirection header("HTTP/1.1 301 Moved Permanently"); } header('Location: '.$this->redirect); exit(); } public function getRedirector(array $urls = null){ $default_urls = array( 'http://www.google.ca' ,'http://ca.yahoo.com/' ,'http://www.bing.com/?cc=ca' ); if($urls != null){ shuffle($urls); return $urls[0]; } else { shuffle($default_urls); return $default_urls[0]; } }}?>
Have Javascript on the new site that detects the referrer and let’s the user the user know to update their bookmarks as the link they tried has been permanently moved.
Wait three to four months with this setup, then cancel the old domain and remove the DNS for it.
SS is giving you a PHP way to conquer the problem but it requires loading a PHP script and running it. It’s like using a “poor man’s RewriteMap”, a redirection facility when there are a large number of redirections required which cannot use Regular Expressions effectively.
IMHO, that’s a last resort - IF you maintain the page name (or something regex can use) in the new domain. If you’re smart, mod_rewrite can handle it for you quickly and efficiently.
As a final note, SPOT ON about not being able to redirect once a domain dies. Keep the domain going long enough to provide PERMANENT redirects to all visitors and SE’s!
I did not know how to do what you suggest, thus the php way as it will work, but I can understand how this may not be the best way as it is limited as/per regex matching.
However, I’ve done a site search in google, and there are pages and pages of results, theres no doubt bookmarks I’m not aware of too so rather than put individual redirects on each page can I do an overall redirect? The query string will be exactly the same, just the domain will of changed.
So could the redirect be something like this, where I can pass the parameters and querystring in the redirect and send them to the archived site:
setRedirect('http://ip address of server/' . 'index.asp?page=1');
Awe that would have made me have to think and I didn’t want to do that! Seriously, I missed that. I have not been participating in this forum too much over the years and need to make more time trolling it to get familiarized with the resources here.
:tup:++ for your your COLOR=#000000 [/COLOR][/B][CENTER][/CENTER]excellent tutorial on Mod Rewrite. I now understand how a rewrite map can be made either in a simple text file or in conjunction with a Db. Very powerful solution, and I understand why you recommend it.
Thanks for that! I’ve had many members comment in a similar vein on the tutorial over the years.
RewriteMap is NOT available to most webmasters as it requires server access (to the server or vhost configuration files) where they can be extremely powerful (using built-in functions like {tolower} and flat files-to-databases and programming) - or EXTREMELY dangerous (syntax errors can stop a server - not something you want on a shared server!). For most, however, all that’s needed is a bit of regex (for “easy” redirections using pattern matching) or using a “handler file” to perform complex (flat file mapping or database look-ups) redirections. In coding, there’s always more than one way to do something but you generally have to have a bit of knowledge where to start looking.