How to Change WordPress Permalink Without Breaking the SEO

Learn how to change the WordPress permalink in an established website without breaking your search engine ranking and structure. We will also learn the options to perform the 301 redirections either using plugin or Nginx.

Case Study

We at Codeforgeek use this permalink structure before.

domain.com/year/month/post-name/

As you can see we included the year and month in our URL which was occupying the space and not good for sites like us. It is more suitable for news based sites.

So I decided to change it to more search engine and user-friendly URL and updated it to this format.

domain.com/post-name/

Clean and simple and more space to included good keywords.

This article will cover how I did that using Nginx 301 redirect and WordPress permalink structure.

Preperation

You need to have the following things sorted before you move ahead.

First, research and figure out the best permalink structure for your site. If your website is tutorials, guides based then permalink which I mentioned above suites well.

Second, make sure you have done it over the weekend or the time when your traffic is a bit less. This is just for precaution that if anything goes wrong we would still have a good window of time to figure out the error.

Changing the permalink

After you have figured out the permalink of your choice. Open your WordPress admin and go to Settings > Permalinks page.

Wordpress permalink structure

Choose your permalink structure and click on Save changes button. WordPress will do the rest.

Main task – 301 Redirect

After updating the WordPress permalink, we need to perform the 301 redirects of old links to new links. This is a crucial step because we need to retain the search engine rankings of the links and not generate 404 errors on the old link.

There are two ways to do the 301 redirects.

  1. Wordpress plugin
  2. Server 301 redirect, Nginx or Apache

Using WordPress plugin

If you want to do the redirection using a WordPress plugin, I highly recommend redirection WordPress plugin.

Install it using your WordPress plugin page and create a new redirect.

redirection-plugin-wordpress-dashboard

You can use a regular expression to perform the match of an existing URL to new URL. Visit this documentation for more information.

Using Nginx 301 Redirect

I used the Nginx 301 redirect. Here is my sample redirect regular expression.

rewrite "/([0-9]{4})/([0-9]{2})/(.*)" https://codeforgeek.com/$3 permanent;

As I mentioned, my old URL consists of year and month and I need to redirect it to the post name only. This regular expression will do the same.

Open the Nginx configuration file. Usually, it should be present in /etc/nginx/conf.d/ directory. It may change depending on your configuration.

Paste the above rewrite in the Nginx Server block and save the file.

Always test the Nginx configuration before making the change live.

sudo nginx -t

If the test is successful, do the Nginx restart.

sudo service nginx restart

Clear your browser cache and do the testing. Old URL should redirect to new URL automatically and all the internal link should redirect as well.

Resubmit Sitemap

Once everything is tested out, resubmit the sitemap with new permalink and Google will take care of the rest.

Further study

How to Build WordPress Theme Using Underscores
How to Build WordPress Plugin – Example App and Live Demo
How to Integrate WordPress with ElasticSearch
Announcing Spark – Content Re-sharing App for WordPress

Conclusion

Changing permalinks is a tricky thing. Do the proper planning and perform the test on some different WordPress environment before actually doing it on live server.