.htacess redirect

Discussion in 'Apache' started by csheppard91, Mar 24, 2007.

  1. #1
    I have two websites x and y. y is my new domain and I want everything from x to redirect to y. For instance, if a user types in www.x.com/test.html then I want to redirect to www.y.com/test.html. Everything is the same, except for the domain name. so no matter what the user types in, I want to just replace the domain part to my new domain.

    Any ideas on this?




    Also, if a page doesn't exist, then how can I redirect to my home page?
     
    csheppard91, Mar 24, 2007 IP
  2. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #2
    On the old domain, you can create a .htaccess file in domain.com/.htaccess containing:
    RewriteEngine On
    RewriteRule . http://www.newdomain.com%{REQUEST_URI} [R=301,L]
    Code (markup):
    That matches every request on that domain, then does a 301 redirect to the new domain with the requested uri.
     
    rodney88, Mar 24, 2007 IP
  3. csheppard91

    csheppard91 Guest

    Messages:
    13
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It still doesn't work :(

    Would the code change if y.com is an addon domain on the same server?
     
    csheppard91, Mar 25, 2007 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
     
    Nintendo, Mar 26, 2007 IP
  5. austinm

    austinm Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    So how could I do this if I am redirecting to a new site that has a different directory structure? i.e. http://www.olddomain.com/old/old to http://www.newdomain.com/new/new

    Thanks!
     
    austinm, Mar 26, 2007 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #6
    If all the URLs are completly different, you're stuck.
     
    Nintendo, Mar 26, 2007 IP