Pretty URLs: Enabling mod_rewrite on Ubuntu

Pretty URLs are URLs that have meaning for human readers, rather than just being seemingly random jibberish only a web server could appreciate. The following is an example of a “pretty” URL:

http://my.blog.com/archive/2007/10/pretty-urls

Note that every part of the URL is relevant for a human reader. For comparison, here’s an example of an “ugly” URL:

http://www.mysite.com/nuke/modules.php?name=Forums&file=posting&mode=quote&p=14488&sid=0293840293840577

To enable the mod_rewrite module in Apache2 on Ubuntu:

(1) Add the rewrite.load to /etc/apache2/mods-enabled/

sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/

(2) Edit the apache configuration for your virtual hosting (/var/www/):

sudo nano /etc/apache2/sites-enabled/000-default

(3) Change the AllowOverride value to “All” for the document root directory:

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# This directive allows us to have apache2’s default start page
# in /apache2-default/, but still have / go to the right place
# Commented out for Ubuntu
#RedirectMatch ^/$ /apache2-default/

(4) Restart the server:

sudo /etc/init.d/apache2 restart

Advertisements

One response to “Pretty URLs: Enabling mod_rewrite on Ubuntu

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s