Transferring content onto different domain - redirect old links?

Hi Folks,

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?


you can go into the cpanel and set it up to forward possibly to a catch all

[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( ''); //instantiate the object and set default redirect
$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() {
    protected function redirect($moved_permanently = 0) {
      if($moved_permanently != 0){
        // Permanent redirection
        header("HTTP/1.1 301 Moved Permanently");
    header('Location: '.$this->redirect);
    public function getRedirector(array $urls = null){
        $default_urls = array(
        if($urls != null){
            return $urls[0];
        } else {
            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.

Hope this helps.


Thanks very much for the replies folks.

Just trying to understand this, the old sites will be online just the domain switched off.

For example, a old url in google would be:

Could I redirect this to the archived site somehow? something like:

Any advice or help much appreciated. Thanks

Hi mattastic,

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 the public DNS being cancelled for the 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:

  1. I try
  2. The public DNS routers point to your server and I connect to it
  3. 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.
  4. 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.
  5. 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.


Hi Steve,

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), 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…

  1. User clicks on a search result in google,,

  2. The DNS directs them to the approriate, 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.

What do you think?

Thanks again for your help :slight_smile:

Hi mattastic,

You are moving in the right direction.

I would do the following:

  1. Set the Public DNS for your new domain
  2. Keep the DNS for your old domain
  3. As your new site will be (I guess) the same content your old site had, then your old site should no longer reference these pages. In place of your old links, put new .php or .asp pages that redirect the users to an appropriate page on the new site. So lets say that your old site had and that content has been moved to then you would need the when a bot or user connects to it, to have redirection code here. I don’t know .asp well so I can’t help you with a redirect in .asp but this is what would need to go in the [URL=“”]

/* This is index.php on the old site */
$o_Redirect = new Redirect();
  case 1:
    $moved_permanently = 1;
    $o_Redirect->go($moved_permanently);  case 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(''); /* 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(            ''            ,''            ,''        );        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.

Hope this helps,


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!



Good suggestion Dk,

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.

Would you be able to provde the OP an example specific to his to, using a rewrite map?


Many thanks again Steve.

My plan is to redirect the DNS and not shut it down - so a user clicks on and regardless of the querystring, it sends them to which will be generic splash page with a link to the old content. http://ip address of old server/

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');

Thanks again

This is the piece of code I was after, just a basic redirect depending upon referrer:

$referer = $_SERVER['HTTP_REFERER'];
if ( $referer == "" ) {
  header("Location:" . $_SERVER['QUERY_STRING']);

What do you think?

Hi mattastic,

Yes this would work using the setRedirect() method.

Yes this looks like it is more along the lines of what DK recommended. This looks as if it would work.




Thanks for all the help, really appreciate it, I’ll let you know how I get on.

Thanks again

Awe that would have made me have to think and I didn’t want to do that! :smiley: 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.


Good luck. Although appreciation is nice, the reason we are here is to help, so glad we could be of assistance!


Hey DK,

: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 this!



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.