tags:

views:

240

answers:

4

The following code gives me an internal server error and I cannot determine why.

RewriteEngine On
SetEnv APPLICATION production
RewriteCond %{ENV:APPLICATION} =production
RewriteRule ^.*$ - [S=1] 
RewriteRule ^(.*)$ html/$1.html

All it should do is take the url

/test

and turn have it reference

/html/test.html

behind the scenes, but only if the environment is production, which is set by the SetEnv

+1  A: 

Maybe my mod rewrite is rusty, but if I understand it, that seems to be doing the opposite of what you are saying. If application is production, then it WON'T rewrite the url (and it skips the Rule that would). I'm not seeing anything that would cause an internal server error though.

To do what you are saying, you would need something like:

RewriteEngine On
SetEnv APPLICATION production
RewriteCond %{ENV:APPLICATION} !=production
RewriteRule ^.*$ - [S=1] 
RewriteRule ^(.*)$ html/$1.html

If you are still having problems, check your apache error log, that has the best info for Internal Server Error 500

Todd Gardner
A: 

Either do it like Todd Gardner said or remove the redundant rule and bind the condition to the second rule:

RewriteEngine On
RewriteCond %{ENV:APPLICATION} =production
RewriteRule ^(.*)$ html/$1.html

Additionally I’d use this rule instead to avoid recursion:

RewriteCond %{ENV:APPLICATION} =production
RewriteRule !^html/ html%{REQUEST_URI}.html
Gumbo
A: 

Turn on mod rewrite logging to get useful errors.

RewriteLog rewrite_log
ReWriteLogLevel 2

Adjust the log level for verbosity.

Darren Greaves
A: 

You have to put quotes around the string to compare it correctly

RewriteCond %{ENV:APPLICATION} !="production"