Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-27-2011, 01:49 PM   PM User | #1
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,615
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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?
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 09-27-2011, 05:23 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,602
Thanks: 2
Thanked 398 Times in 391 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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]
Inigoesdr is offline   Reply With Quote
Old 09-27-2011, 05:56 PM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,615
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:09 PM.


Advertisement
Log in to turn off these ads.