Redirecting old domain to new domain

Discussion in 'Apache' started by Johnburk, Aug 14, 2007.

  1. #1
    I have just moved a domain and would like to know how to redirect everything from the old domain to the new domain.

    With the following code it redirects all pages to the new domain

    
    RewriteCond %{HTTP_HOST} ^.*oldwebsite\.com$ [NC]
    RewriteRule ^(.*)$ http://www.newwebsite.net/$1 [R=301,L]
    Code (markup):
    so oldwebsite.com -> newwebsite.net

    The problem is that oldwebsite.com/folder/file1.html is also -> newwebsite.net

    What is the code for having oldwebsite.com/folder/file1.html automaticly redirecting to newwebsite.net/folder/file1.html
     
    Johnburk, Aug 14, 2007 IP
  2. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I was thinking too complex. The code should be

    Redirect 301 / http://www.newwebsite.net/
    Code (markup):
     
    Johnburk, Aug 14, 2007 IP
  3. powerspike

    powerspike Peon

    Messages:
    312
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #3
    RewriteCond %{HTTP_HOST} ^.*oldwebsite\.com$ [NC]
    RewriteRule ^(.*)$ http://www.newwebsite.net/$1 [R=301,L]

    that seems ok on the surface.

    what is/or isn't it doing correctly ?
     
    powerspike, Aug 14, 2007 IP
  4. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Because it forwards everything to the new domain, not the pages within the domain.

    So olddomain.com/link1/page1.html is forwarded to newdomain.com instead of newdomain.com/link1/page1.html
     
    Johnburk, Aug 16, 2007 IP