Enabling Permalinks on your WordPress Server

Tutorial Difficulty Level    

The URLs of the content you publish on your WordPress website are known as permalinks. Permalinks are what people enter into their browser address bar to view one of your pages (they are the “permanent link” to a single page, you see?). They are also what search engines and other websites use to link to your website. Due to this, they are very important.

You can change the structure of your permalinks at any time. However doing this will change the URL of your pages. There are a few options for what permalink structures WordPress has available, and each of them has its own benefits. No matter what, having clean URLs on your website is very important.

WordPress permalink settings can be found in the main settings menu of the WordPress admin area. In the screenshot below, you can see the five custom permalink structures that WordPress displays as common settings.

WordPress automatically enables the Plain permalink structure after you install WordPress. The number used in the default permalink advises WordPress where the content can be found in your database. To be more specific, the number refers to the ID of the table row in the wp_posts table of your WordPress database (the table prefix for your website will be different if you changed it during the installation process). For example, http://www.yourwebsite.com/?p=50 would refer to the 50th row in your website’s wp_posts table and http://www.yourwebsite.com/?page_id=100 would refer to the 100th.

The default permalink structure is not user-friendly. It is better to refer a visitor to a URL such as http://www.yourwebsite.com/big-news-story/ than http://www.yourwebsite.com/?page_id=54367.

The part at the end of the permalink, i.e. ?p=123, is known as a query string. The question mark is a separator and the part that follows afterwards is the identifying data. In this case, we are identifying content from the database to display.

Despite many people suggesting otherwise, search engines such as Google can and do index URL’s that contain query strings (billions of indexed pages online are testament to this). However, search engines do prefer you to use “friendlier” URLs. And they’re ranked higher in results because of their semantic URL structure. By far the best option then is Post name, which would convert something like http://10.108.154.124/?p=1 to http://10.108.154.124/hello-world/, which is far nicer.

But what if your site throws a “404” error after you do this?

In this case it is incredibly likely your webserver is not configured correctly for permalinks. The first thing to check is the hidden .htaccess file in the WordPress directory (nano /var/www/html/.htaccess). It should look like:

and probably will.  Next we need to make sure the rewrite plugin is enable for the Apache webserver so it knows how to redirect URLs. The command on your Linux server, as root, is

and finally we need to configure Apache correctly so that .htaccess files are allowed to override the default settings. Use nano to edit /etc/apache2/sites-available/000-default.conf and make it look like the following:

Now restart Apache.

You’ll find that all your permalinks are now much friendlier!