WordPress Permalink problem
June 8th, 2008 | by Sean |Perhaps like me you’re new to WordPress, and perhaps like me you thought permalinks are a good idea. Perhaps, like me, you changed your settings so that your blog articles which once were:
http://blog.lolyco.com/sean/?p=9
could look like this:
http://blog.lolyco.com/sean/2008/06/08/google-adsense-down/
So you chose your pretty permalink option (there are many other ways of beautifying your blog URLs), clicked on your blog and disaster – you get 404 Not Found for every link. WordPress has a document that can help you, but if, like me, you go blind and are unable to read helpful documents when you’ve destroyed your own work, here is the specific problem I had. If this works for you, you can go back and re-read the WordPress document and see that it had this answer all along. If it doesn’t work, good luck!
I run WordPress on a Slackware server with Apache 2.0 HTTP server. WordPress uses URL-rewriting to convert pretty permalinks into URLs that can retrieve the correct PHP file and pass it a useful reference to your post. Just like the useful WordPress article says, you must have mod-rewrite enabled on your Apache installation. If you didn’t previously compile httpd with the --enable-rewrite option, do it. That wasn’t my problem, as I could see from the ever-handy phpinfo() function.
You can check that the pretty permalinks function is working in WordPress by editing an existing blog entry or creating a new test article. If you’ve set the option on in the WordPress Dashboard, you’ll see a Permalink label that tells you what the new URL will be. If there’s something wrong with your WordPress installation, then the helpful document says you’ll see some warning message here. I didn’t, I saw the lovely URL I so badly wanted to use.
So WordPress thinks everything is OK, Apache seems to be working correctly, how does the Permalink code work? It all depends on .htaccess files in your webservers document tree. WordPress generates rules for Apache’s Rewrite module to convert incoming pretty URLs to something useful. It puts these rules in the .htaccess file in the root folder of your blog. I could see the rules in the .htaccess file, as you’d expect, since WordPress hadn’t complained about anything when it created the Permalink URL. So why aren’t they working?
In my case, it was because httpd, the Apache webserver program, was ignoring the .htaccess file. Why would it do that? If you’re a responsible admin, you may have read the Apache tutorial on .htaccess files. See this excerpt:
When (not) to use .htaccess files
In general, you should never use
.htaccess
files unless you don’t have access to the main server configuration file.
And that’s it, in a nutshell. If you were previously using only server software that never needed access to server configuration on a per-directory basis, you would have used the
Allowoverride None
directive in your configuration file (usually httpd.conf) to prevent httpd ever following directives in .htaccess files. With this directive in place, those WordPress rewrite rules in your .htaccess files are just never followed. The httpd server tries to locate some content at the pretty URL, and fails.
The solution is easy – for the directory your WordPress blogs are located in, just supply a Directory clause in your httpd.conf like this:
<Directory "/var/www/htdocs/wordpress_root_directory">
AllowOverride FileInfo
</Directory>
Your ‘wordpress_root_directory’ will be different to mine. You could always use ‘AllowOverride All’, but you would be permitting more than you might need. Once I made the change above, all my WordPress Permalink woes were solved.
4 Responses to “WordPress Permalink problem”
By Poon Poi Ming on Jun 11, 2008 | Reply
Hi Seanie, this is really a good article. I was trying to use the html tag but it doesn’t seem to work, even though it doesn’t act out. Can it be made to work for WordPress?
By Sean on Jun 12, 2008 | Reply
Aah – I see! This article starts after the necessary “how to get pretty link URLs in WordPress”. Just go into your Settings, it’s the Permalinks option. Choose one of the pretty link formats, whisper the magic incantation against poorly configured web servers, and click ‘Save Changes’. That’s where all my problems started!
By Poon Poi Ming on Jun 12, 2008 | Reply
Hi Seanie, are you saying that I shouldn’t use the Permalinks option? Your last sentence seems to say, “Don’t touch that feature!”
By Sean on Jun 12, 2008 | Reply
You should absolutely, definitely use it. Pretty permalinks are a joy to behold. If your webhost has set up their webserver as badly as I did, you should absolutely, definitely not blame me for encouraging you to use pretty permalinks. I hope I’ve cleared that up!