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 05-28-2012, 09:24 PM   PM User | #1
abhainn
Banned

 
Join Date: May 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
abhainn is an unknown quantity at this point
.htaccess redirect infinite loop

Hi guys,

I'm completely new to apache and trying to 301 redirect a domain to another domain. I used .htaccess with

Options +FollowSymLinks

RewriteEngine on

RewriteRule (.*) http://www.new-domain.com/$1 [R=301,L]


It created an infinite redirect loop. Then I tried if I could do it page by page:

redirect 301 /page.html http://www.newdomain.com/page.html


The problem seems to be that www.olddomain.com and www.newdomain.com point to the same directory on the server. Request to old domain redirects to new domain, but then reads the same .htaccess file again and and again... Doh

Could anybody help, is there a way around this?

Thanks a million !
abhainn is offline   Reply With Quote
Old 05-29-2012, 01:00 AM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,587
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Then try making it
Code:
RewriteRule !^new-domain.com$ http://www.new-domain.com/$1 [R=301,L]
or
Code:
RewriteCond %{HTTP_HOST} !^new-domain.com$ [NC]
RewriteRule ^(.*)$ http://new-domain.com/$1 [L,R=301]
That also gets rid of the www/no-www duplicate content issue.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 05-29-2012, 08:47 PM   PM User | #3
abhainn
Banned

 
Join Date: May 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
abhainn is an unknown quantity at this point
Quote:
Originally Posted by VIPStephan View Post
Then try making it

Code:
RewriteCond %{HTTP_HOST} !^new-domain.com$ [NC]
RewriteRule ^(.*)$ http://new-domain.com/$1 [L,R=301]
Fantastic. Brilliant. Chuffed.

Thank you so much!
abhainn 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 01:48 PM.


Advertisement
Log in to turn off these ads.