My permalinks are broken! Can I use mod_rewrite to ignore a physical file?

A website I work on recently posted a file at the root of their website named “2011.html.” Now, any 2011 blog posts with the permalink structure of year/month/day/post-name do not work, and instead load the 2011.html file. Trying to bring up the archive at domain.com/2011/ also incorrectly brings up the file. 2010 and other years work as expected.

Is there any way I can use mod_rewrite to only acknowledge this file when 2011.html is explicitly in the URL, and use the standard permalink structure with every other URL so that the blog functionality is restored?

The link to this file was sent out in a marketing e-mail, and is receiving a lot of activity so it can’t be moved or renamed.

2 s
2

The reason that’s happening at all is because of content negotiation. /2011.html wouldn’t normally be accessible through /2011/, but content negotiation is making Apache automatically look for files named 2011 (whatever the extension) when it can’t find the folder before it passes control to WordPress.

This can be quite useful, but if you don’t particularly need content negotiation (WordPress itself doesn’t need it), you can turn it off by adding this to your .htaccess:

Options -MultiViews

If that doesn’t work, or you do need content negotiation, you could rename the 2011.html to something else, and use mod_rewrite to make sure the link still works. E.g. rename 2011.html to happynewyear.html and then add this to your .htaccess (before the other RewriteRules):

RewriteRule ^2011\.html happynewyear.html [L]

Leave a Comment