Archive

Author Archive

Creating “Pretty Permalinks” in WordPress

May 1st, 2009

WordPress documentation includes an article on using Permalinks — providing a nice intro into how to make your blog entries’ URLs more user friendly. For example, a fresh WP 2.7 install uses a post URL in the format: “http://example.com/?p=N” (where N = a post number).

I wanted to make the permalink URLs for our Aptalent Solutions blog a bit friendlier — for instance in the format: “http://example.com/category/post-name/”. Since we are using Apache2 under Linux (2.6 kernel) and WordPress 2.7, we needed to make the following 3 changes:
1) ensure mod_rewrite is enabled in apache2: depending on your distro, mod_rewrite may be off by default. To enable, we needed to edit our apache httpd.conf file and ensure the following line was uncommented:
LoadModule rewrite_module modules/mod_rewrite.so

We then needed to find the mod_rewrite.so file (on our system it was located in the /usr/lib/httpd/modules folder) and copy it to the “modules” folder under apache (using a command such as “cp /usr/lib/httpd/modules/mod_rewrite.so /usr/local/apache2/modules/” (make sure to substitue the location of your apache modules folder).
We  then needed to restart the apache server (…/apache2/bin/apachectl restart), and check that mod_so.c shows up in Apache’s included modules (the command “apachectl -l” will show you which Apache modules are currently loaded). 
2) add an “AllowOverride” directive to the virtualhost entry: we had to make sure that our apache server’s WordPress site entry had the following entry (located within the conf’s <VirtualHost> entry):

 <Directory “/var/www/vhosts/WP-physical-directory/”>

                AllowOverride all

                Options FollowSymLinks

                Order allow,deny

                Allow from all

       </Directory>

Where “WP-physical-directory” is the actual physical folder where your WP site lives.

3) add an .htaccess file: in the root folder of our WordPress installation, we ran the following commands:
touch .htaccess
chmod 755 .htaccess

And finally, in our WordPress admin, under “Settings”, “Permalinks” we chose the “Custom” radio button, and typed “/%category%/%postname%” (without the quote marks) as the custom structure format.

Now we can post a permalink URL such as http://www.aptdev.com/wordpress/creating-pretty-permalinks-in-wordpress

Happy posting.

  • Share/Save/Bookmark

jmoore WordPress