How To Switch Permalink Structure In WordPress Under Ubuntu
So let's say after using your WordPress blog for a while you've decided to change your permalink structure to something more readable than the default ?p=123. There are loads of articles on the Internet suggesting to install Permalinks Migration plug-in. However, I've seen plenty of people complaining about this plug-in not working correctly and generating HTTP 404 Error Message. It didn't work for me either for the first time I installed it, but there's a trick to it I had to figure out on my own. Here's step-by-step instructions:
- Install and activate the plug-in.
- Go to AdminPanel->Options->PermalinksMigration and set the old permanlink structure of your site. In my case I had been using the default permalink structure and so I put /%post_id%/ in here.
- Go to AdminPanel->Options->Permalinks and change the new permalink structure to whatever you want. Different sources suggest different structures for improved Search engine optimization (SEO), but I've settled down for /%postname%-%post_id%.html/
Now this is normally where all the other instructions end and user torture begins. All of the blog entries posted previously using old permalink structure will return HTTP 404 unless redirected to the new structure properly with the help of Permalinks Migration plug-in. So here's the trick. Any operation using permanent URL redirect HTTP 301 requires mod_rewrite to be enabled in your Apache server configuration, which is disabled(?) by default. So for those of you still struggling here's the next step:
- Use locate to find if mod_rewrite.so is available on your server:
sudo locate mod_rewrite.soIt will most likely be found in /usr/lib/apache2/modules.
- Switch to the modes-enabled folder:
cd /etc/apache2/mods-enabledUpdate and open rewrite.load file (you may use any text editor to edit this file)
sudo touch rewrite.load
sudo gedit rewrite.load
- Paste the following line into rewrite.load file:
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
- Then open /etc/apache2/sites-available/default and find the following:
Options Indexes FollowSymLinks MultiViews AllowOverride Noneand change it to
Options Indexes FollowSymLinks MultiViews AllowOverride all
- Finally restart Apache:
sudo /etc/init.d/apache2 restart
Let me know if it doesn't work and I might be able to help with troubleshooting.