Modify WordPress Permalinks with Apache on Ubuntu 10.04

Category : Code · by May 18th, 2011

My site runs WordPress on a Linode instance with Ubuntu 10.04 with nginx as a  front-end proxy to Apache.  (That is, all requests to my machine first hit nginx, which usually serves static files on my Django projects, and then they get re-routed to Apache.)

Today, I wanted to change the link structure on my site so that page resources are more permanent.  I wanted to change the permalinks from:

http://sohanjain.com/?p=N

to

http://sohanjain.com/2011/05/modify-wordpress-permalinks-with-apache-on-ubuntu-10-04/

In wp-admin, go to Settings > Permalinks, and choose from the radio buttons.  I chose “month and name”.  However, when I applied settings and tried to go to a static page like http://sohanjain.com/blog/, I got an HTTP 500 internal server error.

To get permalinks working properly with Apache, you must enable mod_rewrite:
sudo a2enmod mod_rewrite

The command a2enmod just creates symlinks (symbolic links, i.e., ln -s ) between /etc/apache2/mods-available and /etc/apache2/mods-enabled directories.

Finally, add the following to your .htaccess file:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

If you don’t have a .htaccess file, then WordPress can create one for you, given that your root directory has sufficient privileges for WordPress to create files. WordPress will ask to create the file once you update permalinks and it realizes you do not already have a .htaccess file.

Restart apache with sudo /etc/init.d/apache2 restart and you should be good to go.

SHARE :

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>