Fixing Wordpress permalink issues on Ubuntu: A Solution Guide

5:02 PM


Okay, so I came across a situation where I needed to migrate my wordpress site from local to server (in my case which was running on Ubuntu). Everything was working fine until I came across many issues after setting up the site on the server. I had made some changes to the permalinks and now , suddenly, everything just turned into a mess.

Hence I decided to pen down this article in the hope that it may help some of you because I had searched up and down and suffered a lot trying to understand why it was causing issues.

This is the message I got:




Before we proceed on fixing the issues, lets try to put the pieces together now, shall we?



Note: You could really skip this part of the article and come back to it at the end if none of the solutions given in the next heading works.


What Really Happened before the 404


1. You think your permalinks are not cool and SEO-friendly and check the one that fits you well, like you see below:




2. You save the changes.

3. Depending on certain scenarios, you may or may not get this message at the very bottom of your screen.




One reason could be that apache does not allow wordpress to easily change the content of your .htaccess file which resides on your wordpress root folder. 

4. In this case, you would manually have to change the contents. And hence you have to copy the contents listed there and paste it into the .htaccess file.




5. Now the reason you may wonder you don’t see the .htaccess file (along with some others) is because it’s a hidden file.

You may have to make the hidden files visible. (Ctrl+H or google it up to find the way). If its still not visible, you could just create a .htaccess file and paste the contents in. Like given below:




From the above code, <IfModule checks within apache whether the mod_rewrite.c module is included within itself. If it is, the code block runs. Else it does not. (which is the problem I and most of you out there is facing).



Somehow the damage is done. How do I fix the permalink issues?


If you had tried changing permalinks, your .htaccess file will get updated using new rewrite rules. This is generally what should happen, but the reason the 404 error comes is simply because none of the rewrite rules of your .htaccess file gets executed.


Why doesn't the rewrite rules get executed?

Answer: Because the rewrite module in apache is not installed or enabled. 
To check if this is realy the case, go to the “mods-enabled” folder under apache2 folder and check if there is a rewrite.load file existing. If its missing then you don’t have it installed.

Note: throughout the tutorial i am assuming that you have permissions to carry out commands and also you have permissions to edit files. You may come across situations where you would have to do it, so if you get an error stating you do not have permission for carrying out a task, make sure you get access rights.


Enabling mod_rewrite.c module on Apache

1. To do that, simply open up terminal and type in this command :
sudo a2enmod rewrite
This will simply enable the rewrite module in apache.

2. If this was successful, then you could simply restart apache using the below command.
service apache2 restart
or
sudo /etc/init.d/apache2 restart
3. Now refresh your browser and check if your 404 error has vanished. If it has, congratulations.


It still does not work. What do I do now?


Scenario 1: 

If you are still stuck maybe there is one thing you would have forgotten.You should do the following:

1. Give .htaccess files permission to override previous directives

You would generally have to open up httpd.conf file. (I have tried high and low trying to figure out where this file was, but if you don’t find this file, apache2.conf is the file you need to be looking at (in my case)).

If you don't find this file, don't worry According to their documentation, find one of these: 


On Ed/X/Ubuntu 6.06 and Ubuntu Edgy Eft, the "main server configuration file" is /etc/apache2/apache2.conf . 
in the LAMP download about a week ago with Ubuntu 9.10 (Karmic) the default configuration file was /etc/apache2/sites-available/000-default

So feel free to trotter around these folders within apache2 to find the file.

On my server, this is where it resides.




2. Open up the file and locate a section that looks like (fully, partially or almost close) to this:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
</Directory>

3. Replace the “AllowOverride None” with “AllowOverride All. This tells Apache that it's okay to allow.htaccess files to over-ride previous directives.

After the change the piece of code looks like this:



4. You might need to reload or restart (step given above) Apache before this change will have an effect:
sudo /etc/init.d/apache2 reload
Now your .htaccess files in your wordpress root directory will be able to make a difference. Your permalink issues should be sorted by now.


Scenario 2: 

If you got an error message as such after you tried to enable the rewrite module, like this…



... it is probably because your userdir is not enabled in apache. In the apache documentation it says that by default, access to these directories is not enabled.

Lets enable it now.

1. Type into the console the following as you can see in the image:




2. Open your mods-enabled folder under the apache2 folder. You can now see the rewrite.load file has appeared in it.

3. Refresh your browser and now you can see the site running fine.


Scenario 3: 

Maybe your rewrite rules are not included within your .htaccess file or something along that line. Idk. Read the first heading given above to check around a bit.

If none of them also work, I am sorry I don’t think I can find any other way. You may just have to search for more ways.

Eventually you shall come up with a solution like I did.

You Might Also Like

22 comments

  1. Really Nice. Very elegant and thourough documentation.

    ReplyDelete
  2. great...i looking in google and i found this

    ReplyDelete
  3. I'm an Ubuntu first timer and was struggling to get my wordpress installation working. You solved it! Thank you! truely inspiring!

    ReplyDelete
  4. Thank you very much, When I setup wordpress in VPS...this help me a lot.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. My name is Camille bruno Valdez my partner and I have been trying for a baby for over two years now, We were going to a fertility clinic for about 5 months before somebody told us to contact this spell caster who is so powerful, We contacted him at this email; arewaspecialistttemple@gmail.com , for him to help us, then we told him our problem, he told us that we will either conceive in February 2014 or March 2014,but after two years of trying we were at a point where we were willing to try anything. And I'm glad we came to Dr Dahiru, Because his pregnancy spell cast put us at ease, and I honestly believe him, and his gods really helped us as well, I am thankful for all he has done. contact him via email: arewaspecialistttemple@gmail.com if you are trying to get a baby or want your lover back. he has powers to do it, he has done mine,

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Server buddies provides Quality remote server management including troubleshooting, Server Management, Plesk Support, Server Maintenance, Server Monitoring, Server Troubleshooting and support for a large variety of customers at affordable rates. Here are option for Server Management, Server Maintenance, Server Monitoring, Server Troubleshooting, Server Optimization, Plesk Support, Linux Support, cPanel Support and Plesk Support.
    .........

    ReplyDelete
  12. This comment has been removed by a blog administrator.

    ReplyDelete
  13. You describe very well with documentation, really nice presentation. I recently used this wordpress installation service. its helps me alot.

    ReplyDelete
  14. Your blog is really very descriptive in which you have described about several techniques how to fix WordPress. Thanks for your sharing and please keep updating with your views.

    Get Website Fix | repair wordpress

    ReplyDelete
  15. I have not found documentation this thorough "EVER"! very very nice job. I always have problems with my websites permalinks and this is exactly what I needed. Thanks a bunch

    ReplyDelete
  16. Thanks for sharing such beneficial information with us. Your article is really very enjoyable while reading about wordpress fixing and please keep sharing more.

    Website Fix | Fix Hacked Site | Shopping Cart Repair

    ReplyDelete
  17. This is what i needed. great post, very detailed. good job

    ReplyDelete