Fixing Wordpress permalink issues on Ubuntu: A Solution Guide5: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?
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 Apache1. To do that, simply open up terminal and type in this command :
sudo a2enmod rewriteThis 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 restartor
sudo /etc/init.d/apache2 restart3. 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 reloadNow 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.