views:

21

answers:

1

Hey,

I'd like to know why the following htaccess file produces a 500 error:

<IfModule !mod_rewrite.c>
    ErrorDocument 500 "Your_Server_Is_Not_Compatible: Apache does not have mod_rewrite loaded. Please check your Apache setup."
    RedirectMatch 302 .* index.php
</IfModule>

<IfModule mod_rewrite.c>

 RewriteEngine on
 RewriteRule ^(.*)$ versions/0/1/$1

</IfModule>

Thanks thanks in advance

+2  A: 

You get a 500 error because you're causing the server to enter an infinite loop (which it gets angry about, and throws an error to stop).

This is because of your RewriteRule, which will always match:

RewriteRule ^(.*)$ versions/0/1/$1

^(.*)$ matches the value versions/0/1/, so after you perform the initial rewrite, the rule set is re-evaluated and creates a cycle that looks like this:

versions/0/1/something
versions/0/1/versions/0/1/something
versions/0/1/versions/0/1/versions/0/1/something

..and so on.

You should condition your RewriteRule to prevent the looping, perhaps as follows:

 RewriteEngine on
 RewriteCond %{REQUEST_URI} !^/versions
 RewriteRule ^(.*)$ versions/0/1/$1

Also, your ErrorDocument 500 statement doesn't make much sense, as you will never generate a 500 error because you don't have mod_rewrite enabled, since you've surrounded the relevant mod_rewrite directives with <IfModule mod_rewrite.c>.

Tim Stone
You the man, Tim! Right on the money! How dumb I was not to think about that! Well, that's why community-powered web rocks!
fabjoa
BTW, this is what I came up with in case it helps<IfModule mod_rewrite.c> RewriteEngine on # dev # hack to avoid infinite loop RewriteCond %{REQUEST_URI} !/versions/ # redirects to dev RewriteRule ^dev/(.+) versions/0/1/$1 [L] # stable # hack to avoid infinite loop RewriteCond %{REQUEST_URI} !/versions/ # redirects to stable RewriteRule ^(.+) versions/0/0/$1</IfModule>
fabjoa