faqts : Computers : Internet : Web Servers : Apache

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 19 people (47%) answered Yes
Recently 4 of 10 people (40%) answered Yes

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