Archive

Posts Tagged ‘apache’

apache rewrite with and without ending slash

July 1st, 2012 No comments

Due to implementing one of redirects noticed about existing a lot of duplication entries on redirect config files, only different on which is one of them is followed by ‘/’ and other not.
Apache mod_rewrite use the regular expressions, and it can be filled more accurately.

To prevent duplication entries if you asked redirect with ‘/’ and without it may be used quantifier ‘?’ which mean existing 0 or 1 character after which it followed.

You can find a bit more information about mod_rewrite and regular expressions following to link:

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

For example, to rewrite http://www.doxer.org/test and http://www.doxer.org/test/ to http://test.doxer.org, you can just do the following:

RewriteRule ^/test/?$ http://test.doxer.org [L,R=301,NC]

instead of the following:

RewriteRule ^/test$ http://test.doxer.org [L,R=301,NC]
RewriteRule ^/test/$ http://test.doxer.org [L,R=301,NC]

Categories: IT Architecture Tags: