fabjoa
fabjoa

Reputation: 1615

rewrite url issue

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

Upvotes: 0

Views: 47

Answers (1)

Tim Stone
Tim Stone

Reputation: 19169

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>.

Upvotes: 2

Related Questions