WordPress Permalinks Not Working

Posted on in System Administration

Official WordPress LogoWhile setting up a new blog for an old site the other day, I ran into a situation where the main page would work, but individual posts would result in a 404 (page not found) error. Checking the error log revealed that Apache could not find the file it was looking for. For example:

File does not exist: /var/www/wordpress/hello-world/

<!--more-->

The way this should work, when a file is not found, WordPress is invoked via index.php. This is controlled in the .htaccess file in the main WordPress directory. The file contents should look something like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

The final piece of the puzzle is the correct Apache httpd configuration. In my case, the default install of httpd did not allow .htaccess files to be read. This resulted in the main WordPress directory working fine, but permalinks were broken since the web server never referred to the .htaccess file for the rewrite rules. The following changes to the virtual host configuration for this website fixed the problem.

<Directory "/home/httpd/www/wordpress/">
  Options FollowSymLinks
  AllowOverride FileInfo
</Directory>

Adding the AllowOverride was the trick that got my new WordPress install up and working.

Slaptijack's Koding Kraken