I use the “include” method to remove index.php on my site. I was having serious difficulty linking to files in a real directory. To simplify somewhat, I was using code like this in .htaccess:
RewriteEngine on
RewriteCond $1 ^(blog|search|site|P[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
The problem was that the real directory is called “blog_files” so the above code was rewriting any request for a file from that directory.
It took me a long time (six months of occasional frustration), and eventually a nudge from Ingmar to look for the problem in .htaccess. I should have caught this right away, but sometimes the obvious is impossible to see.
So, here’s the lesson to be (re)learned: the ^ in the regex above means “begins with”. It is not an exact match. So, mod_rewrite was seeing the request to “blog_files”, matching it to “blog” and then rewriting it. The result was that I couldn’t link to files in that directory.
The solution was simple once I found the problem. I just added a slash to the end of all of the template group names in the RewriteCond that might match a real directory. So, the resulting code looks like this:
RewriteEngine on
RewriteCond $1 ^(blog\/|search\/|site\/|P[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
That way, it will only match if it sees “blog/” in the URL and it, therefore, won’t attempt to rewrite “blog_files/”.
I think that it is a good idea to do this just in case you might ever create a real directory that might match a template group name.
