Redirect All Pages From Old Domain To New Domain Root

Discussion in 'Site & Server Administration' started by JohnS0N, Dec 11, 2008.

  1. #1
    JohnS0N, Dec 11, 2008 IP
  2. Estevan

    Estevan Peon

    Messages:
    120
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    0
    #2
    hello

    add this lines in .htaccess in olddomain.com

    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www.newdomain.com$
    RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301]

    and all visit are sent to newdomain

    Best
     
    Estevan, Dec 11, 2008 IP
    JohnS0N likes this.
  3. JohnS0N

    JohnS0N Notable Member

    Messages:
    1,581
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    210
    #3
    I tried this one before. Doesn't work properly. Redirects olddomain.com/?p=8 to newdomain.com/?p=8, but I want olddomain.com/?p=8 to newdomain.com (root)
     
    JohnS0N, Dec 11, 2008 IP
  4. Estevan

    Estevan Peon

    Messages:
    120
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    0
    #4
    well

    here is the code to redirect all to main domain
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www.newdomain.com$
    RewriteRule ^(.*)$ http://www.newdomain.com/ [R=301]
     
    Estevan, Dec 11, 2008 IP
  5. JohnS0N

    JohnS0N Notable Member

    Messages:
    1,581
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    210
    #5
    If I see correctly that is the same one as above.
     
    JohnS0N, Dec 11, 2008 IP
  6. JohnS0N

    JohnS0N Notable Member

    Messages:
    1,581
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    210
    #6
    Finally solved it, so here is the solution for any potential future readers.

    The problem is that with standard wordpress you get permalinks with question marks in url, which makes the URL into a query string, which is handled differently than normal forwarding requests in an .htaccess file. The solution is to put a question mark at the end of the RewriteRule. So in this specific case, the file now looks like:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^.*olddomain.com$ [NC]
    RewriteRule ^(.*)$ http://www.newdomain.com? [R=301,L]
     
    JohnS0N, Dec 11, 2008 IP
  7. eXoTic

    eXoTic Peon

    Messages:
    140
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    eXoTic, Apr 30, 2011 IP
  8. readezarchive

    readezarchive Active Member

    Messages:
    600
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #8
    I know this thread is a little old, but I've searched all the other threads on DP and other sites as well and the above example is the best if you are trying to redirect ALL of the pages including inner pages of your site to a new URL. If you have taken a site down that is receiving traffic to various pages of your site and you don't want to simply forward the domain to a new url then add this to an .htaccess file in the root directory:

     
    readezarchive, Oct 24, 2011 IP