I was working on a WordPress site yesterday, mostly in a Web Performance Optimization capacity (on shared hosting).
At one point I noticed that my .htaccess file had redundant, possibly contradictory, directives:
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress # From the HTML5 Boilerplate # https://github.com/h5bp/html5-boilerplate/blob/master/.htaccess # Apache Server Configs v2.0.0 | MIT License # https://github.com/h5bp/server-configs-apache ... # BEGIN WordPress RewriteEngine on # # Unless you have set a different RewriteBase preceding this # point, you may delete or comment-out the following # RewriteBase directive: RewriteBase / # # if request is for image, css, or js file RewriteRule \.(gif|jpe?g|css|js|ico)$ - [L,NC] # or if URL resolves to existing file RewriteCond %{REQUEST_FILENAME} -f [OR] # or if URL resolves to existing directory RewriteCond %{REQUEST_FILENAME} -d # then skip the rewrite to WP RewriteRule ^ - [S=1] # else rewrite the request to WP RewriteRule . /index.php [L] # # END wordpress I omitted the contents of the .htaccess from the HTML5 Boilerplate (the ellipses) as I don't think that code is relevant (I barely touch it, using it largely as is and it works just fine on enough sites that I know it isn't problematic. For reference, it can be found here.
Since the .htaccess file had the default WordPress directives at the top and the "improved" directives at the bottom, which would apply?
I searched Stackoverflow and here and found a couple questions on this point but nothing that ever really answered the order in which directives are processed. Would the one at the top of the file or at the bottom be used?
This is a clear, specific example but I end up with .htaccess files with duplicate code and redundancy often enough that a more general 'rule-of-thumb' answer would be more useful to me than something only applicable to this instance...for instance, I often end up with gzip (compress/mod_deflate) directives with different syntaxes and I have no idea if the order of them matters or not.
I think this site was on Apache 2.2, if helpful.
Thanks