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:
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
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
a2enmod rewrite
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:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Now restart Apache.
/etc/init.d/apache2 restart
You’ll find that all your permalinks are now much friendlier!