Cristofayre
Cristofayre

Reputation: 121

Error in htaccess redirect

The support team at my web host cannot seem to answer this question, so I have done my own research, but not 100% there yet. In short, I'm trying to redirect ANY page on a domain back to index page of that domain. For example ...

http://www.my-domain.com/images/xyz.gif --> http://www.my-domain.com/index.html
http://www.my-domain.com/cgi-bin/xyz.pl --> http://www.my-domain.com/index.html
http://www.my-domain.com/page.html --> http://www.my-domain.com/index.html

I think it's a 301 that I need, either a ReWriteRule or RewriteMatch

Here is the code that I came up with (line 3) and an existing htaccess:

 RewriteCond %{HTTP_HOST} ^eco\-rainbo\.com$ [OR]
 RewriteCond %{HTTP_HOST} ^www\.eco\-rainbo\.com$
 RedirectMatch 301 ^/(.*)$ "http\:\/\/www\.eco\-rainbo\.com\/index\.html"

My limited knowledge of regex is saying "if the HTTP_HOST variable starts with "www.eco-rainbo.com" then ... "if next part of URL there is a forward slash followed by any information then jump to ".../index.html"

It works - of sorts - and goes to the index.html page. However, Firefox complains that the page isn't redirecting correctly "... in a way that will never complete"

Must just be some small item I'm missing from code, but what? NB: I tried a cpanel redirect, but got "my-domain.com/indexhtmlindexhtmlindexhtmlindex.html/page.html"

My Webhost used this - which looks almost the same - but doesn't seem to work

RewriteRule ^\*\.\/?(.*)$ "http\:\/\/www\.eco\-rainbo\.com\/index\.html$1" [R=301,L]

Upvotes: 0

Views: 33

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

You need to exclude the destination you are redirecting to and use RewriteRule instead of RedirectMatch:

 RewriteCond %{HTTP_HOST} ^(www\.)?eco-rainbo\.com$ [NC]

RewriteCond %{REQUEST_URI} !^/index\.html [NC]
RewriteRule ^(.+)$ http://www.eco-rainbo.com/index.html [L,R]

Upvotes: 1

Related Questions