Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Struggling with 301 redirects in .htaccess

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,512
Scotland
Please excuse me if this is not the correct forum for my problem.

I am trying to use .htaccess to redirect an old domain to a new one. The are many pages on the old domain, all in the same root directory. For simplicity, I want to redirect each of these old pages to the home page of the new domain (which is named index.html).

I have tried several variations of the syntax, including the following:

Code:
Redirect 301 / [URL unfurl="true"]http://www.newdomain.com/[/URL]
Redirect 301 / [URL unfurl="true"]http://www.newdomain.com[/URL]
Redirect 301 ^/ [URL unfurl="true"]http://www.newdomain.com/[/URL]
Redirect 301 / [URL unfurl="true"]http://www.newdomain.com/index.html[/URL]
Redirect 301 / [URL unfurl="true"]http://www.newdomain.com/another_page.html[/URL]
Redirect 301 index.htm [URL unfurl="true"]http://www.newdomain.com/index.html[/URL]

Plus all of the above while omitting the [tt]www.[/tt] prefix.

No matter what variation I use, the result is always the same. It correctly finds the new domain, but it always goes to my custom 404 error page.

Can anyone throw any light on this. Clearly, my basic syntax is correct, otherwise it wouldn't be going to the new site, but I don't understand why the new site is always going to the 404. I am sure that index.html exists on the new site and is the default page.

Thanks in advance.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
forum65

You do not need the /index.html after the domain IF 'index.html' is in your list of 'index documents, because your rules will create a closed loop, and as the this is on the same physical server you need to specify when the redirect rule should end using the L flag.

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^old.tld [NC,OR]
RewriteCond %{HTTP_HOST} ^[URL unfurl="true"]www.old.tld[/URL] [NC]
RewriteRule ^(.*)$ [URL unfurl="true"]http://new.tld/$1[/URL] [L,R=301,NC]

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top