Entry
In my .htaccess file, why does 'RewriteRule ^(i)(.*)$ subdir/$1$2' work and RewriteRule ^(.*)$ subdir/$1' not work (i is first letter of file)?
Nov 15th, 2001 18:49
Anthony Boyd, Scott Ayres,
Neither should work. ^(i) should match any URL that begins with "i".
No URLs begin that way. They all begin with a slash. My only guess,
if you're really getting matches that way, is that Apache is nicely
guessing what you meant and covering for you.
The second pattern should end up giving you double slashes. If the URL
requested is "/index.html" (remember, URLs begin with a slash) and you
capture that with ^(.*)$, then when you prepend "subdir/" you get this:
subdir//index.html
Not only can the double-slashes cause a mix-up (but it shouldn't) but
there is another issue with both patterns you've tried. And that is,
your new patterns don't start with a slash. This should cause both
patterns to fail. The RewriteRule I would use is as follows:
RewriteRule ^/(.*)$ /subdir/$1