Apache RewriteRule weirdness
Phenomenally useful post by a guy named Max Dunn in his blog “Eschew Obfuscation”.
The gist of the usefulness for me:
- Let’s say people are accessing your site on the url http://site.com/coolpage and you need to rewrite that to http://site.com/index.php/coolpage
- When your RewriteRule directive is in a conf file, it will be matching against “/coolpage”
- When the directive is in a .htaccess file located in the document root for site.com, it will be matching against “coolpage”
I thought it was pretty weird behavior until I realized: the .htaccess rules will only be applied to requests for things within the site.com document root, (making the leading slash irrelevant information) whereas the the conf files are potentially server-wide.
Here’s what you’d probably use in each case:
Apache conf file:
RewriteRule ^/(.*)$ index.php?/$1 [L]
.htacess file:
RewriteRule ^(.*)$ index.php?/$1 [L]
