Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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]

# END WordPress

# From the HTML5 Boilerplate
# Apache Server Configs v2.0.0 | MIT License


# 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.


share|improve this question

Since RewriteRule . /index.php [L] will catch every request except /, and that'll go to index.php anyway, the second set of rules (bottom of the file) will never apply.

Actually, that's not quite true, but all they'll do is try to skip the index.php rewrite for static files (which wouldn't be happening anyway).

This was probably either a copy-paste error, or Wordpress' automatic management of .htaccess files (such a bad feature) doing something it shouldn't. Delete the second set of rules, it's less accurate, less clear, and just confusing matters.

share|improve this answer
As I understand it, on shared hosting there can be a decent performance improvement by telling the server not to query the database for static assets like CSS, JS, images...and that is what this is supposed to do. Is that incorrect (or negligible)? – adam-asdf Dec 2 '13 at 7:14
@adam-asdf Pretty negligible, since it's just stating the file to determine if it exists. You'd get a much larger performance increase by disabling .htaccess files and moving this configuration into a <Directory> block. – Shane Madden Dec 2 '13 at 17:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.