Home | @unixist | unixist@freenode

>: Apache-Wordpress permalink 404 issue

If you’re running into HTTP 404 errors while trying to configure permalinks (i.e. non-default, http://example.com/month/day/post URLs or similar), it may be due to your Apache configuration.

First solution

The first thing you should check is whether Wordpress’ .htaccess file is setup properly. The least error-prone way to achieve this is to: ensure the .htaccess in your Wordpress directory is writable by the user of the Apache process (usually apache, httpd, or nobody); navigate to your http://example.com/options-permalink.php page; select the desired permalink scheme and click “Save Changes”. This will write a new .htaccess file into the wordpress directory. Now revoke all write permissions to .htaccess with the command chmod oug-w .htaccess.

Now, if you are like I was and can’t yet get your permalinks to give you HTTP 200’s, the next solution may work. I googled this issue previously, but gave up. I came to hate the vague http://example.com/?p=123 post syntax enough to finally take the 10 minutes to fix the problem.

More obscure solution

A few Apache deets first. The main Apache configuration file (if you have multiple config files, it’s the one that includes all the rest, likely apache.conf or httpd.conf) sets various global permissions and capabilities on directories and resources. In order to prevent config files located in sub-directories, which may be owned/writable by regular users, from changing these global settings, there is an Apache configuration keyword called AllowOverride. When set restrictively, .htaccess files in DocumentRoot’s hierarchy are disallowed overrides, preventing potential subversion of the settings in the main config file. But wait, Wordpress permalinks require the use of mod_rewrite. And it turns out mod_rewrite’s directives RewriteEngine, RewriteOptions, RewriteBase, RewriteCond, RewriteRule require the ability to override file information. So let’s explicitly grant this ability by editing the relevant Apache config file to allow the override:

<Directory "/path/to/docroot">
AllowOverride FileInfo

Note that this is only applicable to <Directory> sections. For more information related to the AllowOverride directive or the FileInfo setting in particular, see the relevant Apache documentation