Wednesday, January 26, 2011

What is wrong with my .Htaccess file? I'm trying to redirect permanently my whole site to the index.htm file

This is giving me a 500 internal server error. Any suggestions? I have tried various examples but I think I'm missing something...

RewriteEngine On
RewriteCond  %{request_uri}!^ /index\.htm
RewriteRule  ^(.*) /index\.htm [R=permanent,L]

It displays the homepage if I navigate there but anything that meets the conditions (all appart from index.htm gives the server 500)

EDIT: with the above code it now doesnt give any 500 errors but it doesnt redirect for any pages

  • You're not redirecting to /index.htm, you're redirecting to / which is different as far as Apache is concerned.

    Try: RewriteRule ^(.*)$ /index.htm [R=permanent,L]

    SocialAddict : please can you edit out the domain - i forgot :)
    SocialAddict : Incidently I tried that just before your post with the same issue :(
    SocialAddict : I'm using utf-8 as the .htaccess file type is that correct?
    SocialAddict : still doesn't redirect but displays the original (old) page
    Andy Shellam : What about capitalising REQUEST_URI? It might be case-sensitive, and in all the Apache documentation, those macros ARE IN CAPS (not shouting, just illustrating :-P )
    SocialAddict : tried that now too no luck
  • Your rewrite condition isn't split up well and your Not-StartWith is part of the previous parameter. :) You need a space after the %{REQUEST_URL} and before the !^

    RewriteEngine On
    RewriteCond  %{REQUEST_URI} !^/index\.htm$
    RewriteRule  ^(.*) /index.htm [R=permanent,L]
    
    From Amadiere

0 comments:

Post a Comment