Where to put .htaccess for permalink and the reason

   Posted by: techiecat   in Wordpress

Permalink is definitelty a good idea. When I tried to setup the permalink in my WordPress blog, however, I was frustrated at the beginning. I always got 404 error, mod_rewrite seemed not working. Finally, I found that it is really simple. I was just confused by a statement in the WordPress Document that

WordPress’s index.php and .htaccess files should be together in the directory indicated by the Blog address (URI) setting on your General Options page.

So I put the .htaccess file in the wp-content folder (I did this manually, since I did not want WP having rights to write everything on my disk), since index.php is there. It is wrong! The .htaccess file should be put to the ROOT of your blog — i.e., the top level folder of your wordpress software package.

The reason

Let’s use http://techiecat.catsgarden.net/article/fun-anti-phishing-game.html URL as an example. When Apache gets a request of the URL, it visits the root of this blog and tries to retrieve a document named as fun-anti-phishing-game.html under the article folder. As you know, such document and folder do not exist. So rewrite rules must be applied to redirect Apache to other places. Rewrite rules are contained in the .htaccess file. If .htaccess file is not in the root folder, Apache simply thinks that the retrieval operation fails and gives out 404 error.

What the .htaccess file does in the WordPress is to rewrite the URL as http://techiecat.catsgarden.net/index.php/article/fun-anti-phishing-game.html. index.php is smart and knows how to retrieve article/fun-anti-phishing-game.html.


This entry was posted on Friday, July 11th, 2008 at 4:06 pm and is filed under Wordpress. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply

Mail (will not be published)