Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,485
    Thanks
    6
    Thanked 981 Times in 954 Posts

    htaccess 301 domain redirect not quite working

    OK, I have two domains, let’s say example1.com and example2.com. Both are accessing the same webspace. Domain 1 used to be the default domain for years, now I want to make domain 2 the default and redirect domain 1 to domain 2. Additionally, I had a www-to-non-www redirection in place for domain1 and of course I want to keep this (for the new domain and the redirection from old to new).

    I have the following rule in my htaccess file:
    Code:
    RewriteCond %{HTTP_HOST} !^example1.com$ [NC]
    RewriteCond %{HTTP_HOST} !^example2.com$ [NC]
    RewriteRule ^(.*)$ http://example2.com/$1 [L,R=301]
    Now, this is correctly redirecting both, http://www.example1.com and http://www.example2.com to http://example2.com but it’s not redirecting http://example1.com (without www) to domain 2.

    How can I achieve what I want?

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Unless I'm missing something just omit that first condition:
    Code:
    RewriteCond %{HTTP_HOST} !^example2.com$ [NC]
    RewriteRule ^(.*)$ http://example2.com/$1 [L,R=301]

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,485
    Thanks
    6
    Thanked 981 Times in 954 Posts
    Ah, hmm… that’s interesting. Why does this work?

    Oh, I think I get it. It says “if HTTP_HOST is not example2.com redirect to http://example2.com”, right. Stupid me! That’s why originally it always used to redirect to domain 1 when domain 2 was added.

    I’m gonna go now and bang my head against the wall.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •