Forum Moderators: phranque
Here is what I have at the moment (in the order listed), and it seems to work, but I don't want to cause trouble down the road:
1) rewrite to canonical URL
2) rewrite to remove "index.php?" from the URLs created by my new CMS.
3) several rewrites for specific files to their new locations
4) a couple of AddHandler statements to force *.php files to run under PHP 5 instead of PHP 4.
Is that the correct order, or am I asking for trouble?
Thanks,
Tim
Only the order of directives belonging to the same module (e.g mod_rewrite) are of any consequence; The server configuration specifies which modules will process your .htaccess file, and in what order they will do so. As a result, it's generally best to group all directives belonging to the same module together, just to keep them organized.
For more info, see the Apache documentation for the LoadModule directive.
Jim
I suggest putting your script rewriting rules in order from most-specific to least specific, and using unambiguous regex patterns wherever possible -- and that means "most of the time." -- In addition to preventing unexpected matches and the resulting problems, they also offer a very-significant processing-speed advantage in many cases.
- redirect all URLs in parameter-based formats to folder-based format at www of correct domain (and with no parameters in target).
- redirect named index files to "/" at www, preserving folder names, and strip parameters.
- redirect non-www and www on other domains to www on correct domain, preserve filepath and filename, and strip parameters.
- redirect non-www on this domain to www on this domain, preserve filepath and filename, and strip parameters.
- redirect URL. Strip parameters from www URL, leave rest of URL intact.
- internally rewrite folder based URLs to internal filenames with attached parameters. These are *NOT* URLs.
Each rule has [L] at the end.
Trace what happens for a non-www index file. It gets redirected to www and then it gets redirected again to remove the filename.
See my post above for one better way to do it. There is no single one right way, but there are very many incorrect ways to do it.