With a little side of applesauce...

Monday, January 29, 2007

Apache mod_rewrite - Rewrite everything except a specified subdirectory

If you need to rewrite everything except for a specified subdirectory, you use:

# Don’t rewrite if the %{REQUEST_FILENAME} is /health
RewriteCond %{REQUEST_FILENAME} !health(.*)
RewriteRule ^/(.*)$ https://www.example.com/$1 [R]

This tells Apache to rewrite everything except for the /health directory on www.example.com.

http://www.example.com/ # rewrites to

- > https://www.example.com/

http://www.example.com/stats # rewrites to

- > https://www.example.com/stats

http://www.example.com/health/index.htm # doesn’t rewrite

- > http://www.example.com/health/index.htm

http://www.example.com/health # doesn’t rewrite

- > http://www.example.com/health

No comments: