Question

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

No correct solution

OTHER TIPS

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

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

Turn on mod rewrite logging to get useful errors.

RewriteLog rewrite_log
ReWriteLogLevel 2

Adjust the log level for verbosity.

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

RewriteCond %{ENV:APPLICATION} !="production"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top