How do I redirect all visitors to mysite.com to mysite.com/page2.html ?
I seem to end up with a loop using
RewriteRule ^(.*) page2.html [L,R=301]
which I know is probably a stupid code but how should I do it then?
How do I redirect all visitors to mysite.com to mysite.com/page2.html ?
I seem to end up with a loop using
RewriteRule ^(.*) page2.html [L,R=301]
which I know is probably a stupid code but how should I do it then?
The problem with that code is that it will also redirect page2.html to page2.html, then redirect to page2.html, again, and again, etc. Max 10 times and then Apache gives you the 500 internal server error doesn’t it?
The solution is rather simple, redirect everything except page2.html to page2.html
RewriteEngine On
# If the current request is not for test2.html ...
RewriteRule %{REQUEST_URI} !^test2\\.html
# ... redirect to test2.html
RewriteRule .? page2.html [L,R=301]
I also changed ^(.) to .? – if you don’t an atom, don’t create it
Plus, (.) is EVIL, but we’ll save that for another time okay?
What imgurume is describing is the DirectoryIndex of his domain.
It’s more important to use the correct tool, i.e., the one designed for the problem at hand.
Regards,
DK