How to Change Permalink Structure and Setup Redirects in WordPress
Last month, I changed the month and year based permalink structure of TechTage to a simpler one based on just the post name. When I initially changed the structure from WordPress settings, I was quick to notice that old links were not working any more. With a quick .htaccess tweak, I was able to fix that and so far all my old URLs are 301 redirecting to the current ones. This was a lot easier to achieve than I had anticipated, and I’m going to show how you can do it too in this post.
NOTE: This tutorial is only for switching from a different permalink structure to the simple %postname% structure. In some cases like when you’re switching from a less to more informative URL structure, you don’t actually have to setup redirects manually tweaking your .htaccess. WordPress automatically handles the job for you. Test (load your old URLs) before you proceed!
Here are the steps:
1. Choose the ‘/%postname%/’ Structure from in WordPress ‘Permalink Settings’
The title explains it all. You just check the box next to ‘/%postname%/’ and click on ‘save changes’ at the bottom.
2. Use Yoast’s Redirects Generator
The most useful tool for the purpose, hands down.
- Click on the green ‘generate redirects’ button at the bottom of the post.
- Input your site’s URL.
- Specify if your blog is running in a subfolder (such as /blog).
- Select your old permalink structure.
- Generate the code responsible for the redirect.
The code looks something like this:
3. Modify Your .htaccess
The last step involves adding the previously generated piece of code to the .htaccess file of the root directory of your WordPress installation. You can do this via a control panel (like cPanel) or FTP.
This shouldn’t be hard. All you’ll need to do is to open the old .htaccess file, and add the code to the top of it (yeah, of course you need to save the changes!).
That’s pretty much all. A nice and easy way to introduce the next level of simplicity to your site’s URL structure, and it involves only three steps!
Let me know how it goes for you, in case you try this. Also let us all know if you happen to know about an even easier process to achieve the same result.