Welcome to WebmasterWorld Guest from 54.227.68.206

Forum Moderators: phranque

Message Too Old, No Replies

Redirects For Fun And Profit - Part 1

FAQ: How to move a site to a new domain?

     
7:12 pm on Jun 16, 2004 (gmt 0)

Administrator from CA 

WebmasterWorld Administrator bakedjake is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 8, 2003
posts:3878
votes: 56


Commonly Used Redirects For Moving To A New Domain

Most of these are lifted from, slightly modified, or examplified forms of posts here at WebmasterWorld and summarized here for reference. Thanks to skipfactor, pageoneresults, korkus2000, Xoc, jdMorgan, Decius, and Daiman for their posts on these topics.

Case: You are transferring from www.example-old.com to www.example-new.com. The architecture of the site will remain the same - you simply want to switch to a new domain name. You want to pass related page and parameter information.

Server Level Redirects

Apache (mod_rewrite)

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.example-new.com/$1 [R=301,L]

IIS (Built In Rewrite Module)

  • Right click on site (www.example-old.com) in IIS Manager, select Properties
  • Click on "Home Directory" tab
  • Select the "A redirection to a URL" option
  • In the "Redirect to" box, place the text

    http://www.example-new.com$V$Q

  • Select the "The exact URL entered above" option
  • Select the "A permanent redirection for this resource" option

    Language Specific Redirects

    see below

    [edited by: oilman at 8:18 pm (utc) on June 16, 2004]

  • 7:34 pm on June 16, 2004 (gmt 0)

    Administrator from CA 

    WebmasterWorld Administrator bakedjake is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

    joined:Apr 8, 2003
    posts:3878
    votes: 56


    This PHP code should handle any parameters:

    <?php

    [pre]header("HTTP/1.1 301 Moved Permanently"); 
    header("Location: http://www.example-new.com" .
    $_SERVER['SCRIPT_NAME'] . '?' .
    $_SERVER['QUERY_STRING']);
    exit();
    [/pre]

    ?>
    7:43 pm on June 16, 2004 (gmt 0)

    Administrator from CA 

    WebmasterWorld Administrator bakedjake is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

    joined:Apr 8, 2003
    posts:3878
    votes: 56


    This Perl code should handle any parameters:

    print "Status: 301 Moved Permanently\r\n" . 
    "Location: http://www.example-new.com" .
    "$ENV{'SCRIPT_NAME'}?$ENV{'QUERY_STRING'}\r\n" .
    "\r\n";

    [edited by: oilman at 8:23 pm (utc) on June 16, 2004]

    7:59 pm on June 16, 2004 (gmt 0)

    Administrator from CA 

    WebmasterWorld Administrator bakedjake is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

    joined:Apr 8, 2003
    posts:3878
    votes: 56


    This ASP code should handle any parameters:

    <% 
    Response.Status = "301 Moved Permanently"
    Response.AddHeader "Location", "http://www.example-new.com" _
    & Request.ServerVariables("SCRIPT_NAME") _
    & "?" & Request.ServerVariables("QUERY_STRING")
    Response.End
    %>
    7:16 pm on July 1, 2004 (gmt 0)

    Full Member

    10+ Year Member

    joined:Feb 11, 2003
    posts:217
    votes: 0


    Yes but what about when they are changing the directory structure :( Shall be a pain to keep my listings and traffic going while we do this.