5 Simple Steps to Configure WordPress To Use Permalinks On An Ubuntu Server

Having clean URLs for you wordpress website helps your visitors navigate your site easier as well as improve Search Engine Optimization (SEO). In this tutorial we will look at how to set this up on your WordPress site running on an Ubuntu server.

Here is an example. You can see the page URL is /?page_id=4



Example of default WordPress query URL




After making some changes to the permalink settings the URL are easier to remember and more SEO friendly.



Example of a clean URL using permalinks in WordPress





To enable permilinks we need to have an .htaccess file. For the .htaccess file to work we need to enable AllowOverride in the Apache config and set the correct permissions on the .htaccess file.




1.) Apache Configuration:

Let’s start by enabling AllowOverride in the default virtual site file. This default file is located at /etc/apache2/sites-available/default. To keep things simple we will use the nano text editor. If you preffer to use Vim or Emacs feel free to do so.

sudo nano /etc/sites-available/default



edit /etc/apache2/sites-available/default



Enter your password



Enter your password



We need to change AllowOverride None to AllowOverride All in two places.



Chane AllowOverride none to AllowOverride All



Example of Apache default file



Once you made your changes, hit CTRL + X to exit nano

Hit “Y” to save your changes



Enter Y to save changes



Hit Enter to overwrite the file



Hit Enter to overwrite the file



Next we will need to enable Apache Rewrite module.

sudo a2enmod rewrite



Enable apache mod rewrite in apache



Apache mod rewrite enable on Ubuntu server






2.) Create .htaccess File:

Ok it is now time to create the .htaccess file. We will use the touch commnad. This allows us to create a blank file quickly.

sudo touch /var/www/.httaccess



Create .htaccess file with the touch command in ubuntu







3.) Setting .htaccess File Permissions:

We will now need to change the owner of the .htaccess file to www-data, the user that apache runs under as default. We will also need to change the permissions on the file to 664.

sudo chown www-data:www-data /var/www/.httaccess



Change the owner of .htaccess on ubuntu server



Now set the permissions on the file to 664

sudo chmod 664 /var/www/.httaccess



Change permissions to .htaccess file to 664






4.) Restart Apache Web Server:

To make the changes take effect we will now need to restart the Apache web service.

sudo /etc/init.d/apache2 restart



Restart Apache /sudo /etc/init.d/apache2 restart



You should see OK if it started correct



Apache restarted .. OK







5.) Setting Up Permalinks Settings In WordPress:

Login to your Admin interface on your wordpress site. Example URL: http://YourSite.com/wp-admin



Login to the admin interface



Click Settings > Permalinks



Click settings  > Permalinks



You can see by default that it uses a query parameter. We will want to change this to something human readable like postname. Keep in mind you can't have more then one post or page with the same name. In this example we will also include the year to help prevent duplicate names. 

For some common permilink structure tags take a look at http://codex.wordpress.org/Using_Permalinks



Example of default permalink settings in wordpress



Here is my example of setting the default URL's to be /Year/PostName so for http://mywebsite.com/2012/about



Example permalink settings in wordpress



Save your settings and test by navigating to some pages on your site.



Example of Clean URL on Wordpress



If you enjoyed this post, please share it on your favorite social network by clicking on the “Share / Save” bar below.






Other Useful Articles:

How to Install WordPress on Ubuntu: http://mixeduperic.com/ubuntu/simple-steps-to-installing-and-configuring-a-website-using-wordpress-and-ubuntu.html

How to Start and Stop Apache and MySQL commands: http://mixeduperic.com/ubuntu/how-to-start-stop-and-restart-apache-and-mysql-on-ubuntu.html