TECHNOPHILE

Riddling with WordPress permalink setup issues

WordPress is by far one of the best blogging platforms because of its easiness to use, easily available plug-ins and moreover the open source availability. I would later write an article on setting up a WordPress blog for free on a free aws instance.

Now lets move on to the topic.

What are permalinks?

A permalink as the name suggests is a permanent link or a permanent url to your blogs and posts. You can observe the url bar while reading this post. Here https://www.wst.space/riddling-with-wordpress-permalink-setup-issues/ is the permalink of this post. WordPress allows us to customize the format of permalinks. You can do this on wp-admin: Settings>Permalinks.

wrdpress permalink

What happens when you change the permalink settings?

When the permalink format is changed your path settings will also be changed. For example I changed my settings from Month and Name to Post name. That means Initially this post’s permalink was https://www.wst.space/2018/05/riddling-with-wordpress-permalink-setup-issues/ and now it is being changed to https://www.wst.space/riddling-with-wordpress-permalink-setup-issues/.

So this change of settings should be informed to the server. Otherwise the server won’t understand where to look for the particular post. Ideally WordPress will tell the server to make necessary changes while we are saving the new permalink setting by writing it to a .htaccess file. This can be viewed by logging into your server and go the directory containing WordPress installation.

$ cd /var/www/html/

Now use your favorite commandline text editor to open the .htaccess file

$ nano .htaccess

If everything went well, you have successfully changed your site’s permalink.

Why am I getting a 404 error after changing the permalink settings?

I came across this error and I was totally out of ideas why this is happening. After a little research I have found the solution. Basically 404 error happens because of 2 reasons.

  1. WordPress didn’t generate a .htaccess file for you. This is highly unlikely. You can check if there exist an htaccess file in your WordPress home directory as shown above. If it is not there create one:

    $ sudo nano /var/www/html/.htaccess
    and copy paste the below to it# 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 WordPressPress ctrl+x and press y to save the file. And restart apache by

    $ sudo service apache2 restart

    Done
  2. The generated htaccess file is not being followed by server

    This was the mistake I came across with. You need to tell apache explicitly to follow the .htaccess file. You can do this by editing the apache2.conf file. If you are on Ubuntu,

    $sudo nano /etc/apache2/apache.conf

    Scroll down to the line <Directory /var/www/>
    By default it will be:

    <Directory /var/www/>

    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
    </Directory>change the value of AllowOverride to All so now it becomes:

    <Directory /var/www/>

    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
    </Directory>Press ctrl+x and press y to save the configuration file. In order to make this changes to server first enable the mod_rewrite by.

    $ sudo a2enmod rewrite
    And then restart the server

    $ sudo service apache2 restart

    Done!

Leave a Reply

Your email address will not be published. Required fields are marked *