After hosting my website on Plone and attempting to host it on plain HTML5 I decided that time has come for me to use a CMS. As I wrote in the Hello World post (i.e. the first post) I chose to use WordPress. I installed it and as my work and life made me busier and busier, I kind of ignored. It is very apparent from the irregularity of the posts and blank periods in the posting.
Anyhow, the point is that I didn't realize that the permalinks, categories and tags were not working. When I clicked on a particular post or tags or categories, it showed me a 404 error. So essentially I had a broken site on my hands. And here I was wondering why my site was not coming up in searches and why I was not getting any traffic. SEO helps Google to crawl and index the website most effectively when permalinks, tags and categories are setup correctly.
Apparently, it is a very common error in WordPress with a very straight forward solution. A simple google search most likely leads you to the right solution. My objective is not to add to the burgeoning posts of "How to fix 404 errors on WordPress". The objective of this how-to is to address one edge case that will occur when you are trying to host WordPress on your own server/computer.
I followed a lot of posts and almost all of them told me the same thing.
- Re-save the permalink settings and
- Ensure you have the .htaccess in your WordPress directory (some of them don't tell that you should have it in the WordPress directory though).
I was at my wits end on what to do to solve the problem. I was about to give up and try and reinstall WordPress when I came across this site and the how-to. That how-to does address the edge case of people like me who like to run their own web servers instead of buying managed hosting. In fact, I am running my site in containers. In fact re-installing WordPress would have added work and would have broken my site. Thankfully I stayed away from it.
The rewrite module of Apache is not automatically enabled. This was the "A-HA" moment for me. I checked out the modules that were loaded by running
sudo apachectl -L and sure enough there was no rewrite module enabled there. I double checked that I had the rewrite module binary in the
mods-available directory in my Apache distribution.
At this point, I was ready to enable the module by running
sudo a2enmod rewrite and
sudo service apache2 restart on my server and enable the module. After that, I was able to reset the permalinks to whatever I wanted it to be. This fix also worked tags and categories.
I hope this helps whoever is facing this issue.