Home > IT Architecture > apache rewrite with and without ending slash

apache rewrite with and without ending slash

July 1st, 2012

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:
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]

Good Luck!

Categories: IT Architecture Tags:
Comments are closed.