Debug: WordPress permalinks not working

Santosh

2015/08/28

Categories: Linux

So, you have just setup a WordPress site and you want to just get rid of p=1 or index.php from your URLs. You might have already searched over internet and found out how to enable pretty permalinks in WordPress. Everything worked as expected? Cool. Move to next step and start generating the awesome stuff. This article is not for you.

Are you still reading? I think then you are trying to figure out why didn’t it work for you. We will go together for some steps and try to fix this problem. This article is assuming that you are using Apached Web server. You may want to follow these steps in order, if you haven’t completed them already.

Go to Wordpress Admin -> Settings -> Permalink and choose the right permalink structure for you and click save. Are you seeing any message asking you to update the .htacces file? This happens when Apache web server process do not have permissions to edit the .htaccess file. Just copy the content displayed inside WordPress permalink admin page and paste it into the .htaccess file present in the same directory where your WordPress index.php is present. You can access the .htaccess file using ftp or ssh based on your hosting provider. If this file is not already present, you can create a new file and paste the content into it.

Are you using self managed hosting services? Did you install the LAMP stack yourself? Did you enable mod_rewrite in Apache? mod_rewrite is the module used by Apache to perform URL rewriting using the rules specified in the .htaccess file. You can perform this check using phpinfo() function of php.

Copy the following code in a file (let call it mod_test.php) and place it to may be your WordPress root).

<?php phpinfo();?>

Now go to http://you-url/mod_test.php and you should see a phpinfo page. Under configuration section, you should be able to see Loaded Modules. Is mod_rewrite present there?If yes, move to next step. Else, you need to enable this module. On Ubuntu, you run following commands to enable mod_rewrite.

sudo a2enmod rewrite
# Restart the apache server
sudo server apache2 restart

This should have the mod_rewrite enabled for you. You can verify it using phpinfo() as already done. Did this resolve the issue with the permalink?

Note: In a shared hosting, you might not be able to run phpinfo() or might not be able to install the mod_rewrite module. Please contact the support of your hosting provider.

So looks like you are not using managed services and might have tried to install WordPress on a self managed server. Did you create virtual host configuration file properly? You can edit the default config file using below command:

sudo nano /etc/apache2/sites-available/000-default.conf

The file name may vary if you have configure the virtualhost using a different file. In this file the content should be:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ServerName server_domain_name_or_IP
    <!--Important part to enable URL override using .htaccess file -->AllowOverride All
    <Directory /var/www/html/>
        AllowOverride All
    </Directory>
    .....

Please focus on the part after the “Importance” comment. This part enables the URL override based on .htaccess file in your WordPress directory. You may want to change the /var/www/html/ to your WordPress installation part. This was the step which resolved for me it in the worst case faced by me.

Please let me know if this guide was helpful. Feedback is most welcome. Please let me know if  you are still not able to resolve it or seeing any error in following above steps.