Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

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]
share|improve this answer
    
Disabling content negotiation worked great, thanks! –  Nate Dudek Jan 7 '11 at 13:08
    
Great answer! –  MathSmath Jan 11 '11 at 23:49
add comment

Yes, this is exactly the type of thing mod_rewrite was designed to do. However, you will need to move the blog content to another location.

For instance, if /2011/11/1/how-to-brew-beer.html was one of the blog articles, it's no longer accessible there as that's now a broken link. So you'll have to move it somewhere else:

   /2011_good/11/1/how-to-brew-beer.html

Your rewrite rule will need to match anything beginning with /2011/.* and rewrite it to the URL I posted above, assuming that's the location where the articles have moved to.

Moving the content could turn out to be a lot of work. I actually think you're a lot better off just moving the 2011.html file somewhere else and then using a rewrite rule for it since it's just one file as opposed to any historical information.

Of course, we're 7 days into 2011 right now, so I can't possibly imagine there are that many posts to migrate for 2011 :)

share|improve this answer
add comment

Your Answer

 
discard

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.