Select Page

WordPress Category Archive Slug Edit And 301 Redirect Tutorial

by | Feb 25, 2021 | Redirects, Tutorial, WordPress | 0 comments

In this tutorial, I’ll show how to change the slug of a category archive in WordPress. For example, say you have a category archive with the URL:

https://yoursite.com/fruit-and-vegetables/

and you want to make the URL shorter and neater like:

https://yoursite.com/produce/

You’ll need to do two main things for this. The first is edit the category to change the slug, and second is to create a redirect from the old category slug to the new slug. What’s the redirect for? When you change the slug, you are essentially deleting a link to a page on your site. Anyone with the old link cannot access the content anymore. If it’s a brand new website, this isn’t a big deal as it’s unlikely anyone has the old link. For an established website you may end up with thousands of visitors landing on a broken page. Not only that, it will negatively affect your SEO as search engines down rank websites with missing or broken content.

Category Slug Editing And Redirection Video Tutorial

You can follow along with the video or continue with the writtern tutorial below.

Editing The Category Slug

To edit the category slug, go into your WordPress admin dashboard. Under Posts, click Categories.

WP Admin > Posts > Categories

In the Categories Archive hover over the Category you want to edit (In this case ‘Fruit And Vegetable’) and click ‘Edit’ in the options that appear.

In the Category Editor, change the ‘Slug’ field to whatever you want it to be. Here, we’re changing ‘fruit-and-vegetable’ to ‘produce’. After that click ‘Update’.

Hurray! You’ve set the new slug, but now you’ve broken the old one. Any pages that link to the old slug will now point to a 404 page because there is no longer a category page at the slug. To fix this, you’ll need to create a redirect. Either using a plugin or with code.

Creating A Redirect With A Plugin.

I recommend the plugin called (surprise, surprise!) Redirection by John Godley.

Install and activate the Redirection plugin. Next, in the WordPress admin dashboard go to Tools > Redirection.

Admin > Tools > Redirection

The first time you open the Redirection plugin admin page, it will show a welcome screen with information on how the plugin works. You can go through the information but you don’t need to. At the bottom of the screen click the button ‘Start Setup’ to launch the setup wizard.

On the ‘Basic Setup’ screen click the checkbox to ‘Monitor permalink changes on WordPress Posts and pages’, then click the ‘Continue Setup’ button

The next screen ‘REST API’ shows information about how the plugin works with WordPress to do more advanced redirects. You don’t need to worry about the REST API it’s not needed for what we’re doing. If there are any warnings or error messages, you can ignore them for this situation. Click ‘Finish Setup’.

The Plugin will take a moment to set up, then you can click ‘Finished!’ once it’s done

Next, You’ll land on the plugin’s settings page. Switch to the Redirects tab on the plugin navigation.

Redirection Settings Menu

Scroll down to the ‘Add New Redirection’ sub-heading. This is where you’ll enter your Redirects. In the ‘Source URL’ field enter the old slug; be sure to include the forward slash at the beginning and end of the slug. Next, enter the new slug in the ‘target URL’ field. Then click Add redirect and you’re done! Now when you try to visit the old category URL you’ll land on the new category URL.

Creating A Redirect With Server Configuration Code

Apache and Nginx are the server setups that most hosting companies use, so the following advice is for how to set redirects on servers with them.

Category Slug Redirect Code For Apache

Add a code snippet structured like the following to your root .htaccess file:

RewriteEngine on
RewriteBase /
RewriteRule ^old_slug/(.*) http://www.example.com/new_slug/$1 [R=301,L]

Category Slug Redirect Code For Nginx

Add a code snippet structured like the one below to your Nginx conf file. The location of the Nginx conf file varies depending on your setup. Contact your hosting support if you need a hand.

location /old_slug {
  rewrite ^/old_slug/(.*) http://www.example.com/new_slug/$1 redirect;
}

301 Redirects

An important point to note is that the URL should have a 301 redirect status code. This tells anyone trying to access a page that it permanently moved to a new location. The redirection plugin and code snippets I provided take care of the 301 URL redirection status code, but if you are setting up a different redirection, be sure to use the correct status code.

Conclusion

A word of caution. Redirects are a powerful tool, use them with restraint. Be careful not to create chains of redirects by renaming a slug multiple times. When a redirect chain gets too long, browsers stop loading your content and it negatively affects your SEO.

When done right, editing the slug and adding redirects, improves the structure of your site, making it easier for people to browse and for search engines to crawl. That’s a win worth the effort!

If you have questions or had any challenges setting up redirects, let me know in the comments section below.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *