Rewrite module to handle site version folders (strip slash) Rewrite module to handle site version folders (strip slash) apache apache

Rewrite module to handle site version folders (strip slash)


It looks like this is interfering with mod_dir, which by default redirects the browser when it tried to access a directory and the trailing slash is missing. What's happening is the Rewrite is occuring, changing /site to /versions/020/site then mod_dir is redirecting the browser to http://domain.com/versions/020/site/. Thus the browser sees the versions/020 stuff in the location bar.

You can turn off mod_dir's automatic redirect with the "DirectorySlash Off" directive. But you may want to add the trailing slash anyways by including a redirect before any rewrites happen.

RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^(.+[^/])$ $1/ [R,L]

This or something equivalent before you do the rewrite to /version/020 should hopefully fix it.

Edit: Actually, now that I'm thinking about it, if you rewrite/redirect when trailing slash is missing, you don't need to turn off DirectorySlash because it'll always have a trailing slash by the time it gets to mod_dir. Maybe do it anyways to be safe?