How to Add a Prefix to Blog Post URLs (WordPress)
In some situations, you may want to add a prefix to your blog post URLs. This helps categorize your posts separately from the other pages on your site.
Here’s how to make it happen!
Video Tutorial
Preparation
Before we get started, there are some preparations you should take before setting the URL prefix.
First, take a full website backup. This will keep your site protected if something goes wrong.
Next, if you already have live posts that could be indexed in search engines or shared anywhere on the internet, you’ll need to set up redirects.
When you change the URL structure, your old post links will no longer work. To fix this, we will implement redirects from the old posts URLs to the new URLs (with the prefix).
1. Install “redirection” Plugin
To help you set up the redirects, I recommend using Redirection by John Godley.
If you don’t want to use a plugin, you can also set up redirects through your .htaccess file, but that is an advanced method.
After activating the plugin, you’ll see a notification at the top of your WordPress dashboard that says “Please complete your Redirection setup to activate the plugin.”
Click “Redirection setup” and complete the guided configuration process.
2. Get List of Post URLs
You’ll need a list of your current post URLs to set up the redirects later in this article.
Typically, the easiest way to get the URLs is by accessing your sitemap, which can be found by adding /sitemap.xml or /wp-sitemap.xml to the end of your domain name.
Once you are viewing your sitemap, you’ll see several sitemaps within it. Locate your post sitemap.
Now, you’ll be looking at a list of all blog post URLs on your site. You will need to set up redirects for each of these after adding the prefix.
Now that you’re ready to set up redirects, let’s set the prefix.
Setting the Prefix
To set your post URL prefix, visit your WordPress dashboard. In the left sidebar, hover over Settings and select Permalinks.
In most cases, you’ll be using the “Post name” permalink structure. However, take note if you’re using a difference structure.
Select Custom structure. Then, input your desired URL prefix. In this case, we are using /blog/.
Next, input the appropriate tag based on your previously selected permalink structure. In our case, this is %postname%. Also, add a final / to the end of the input.
The finished input is /blog/%postname%/, as seen in the image below.
Double-check your input, then press Save Changes. Your URL prefix is now live!
Setting Up Redirects
Now that your URL prefix is set up, you’ll need to redirect the list of post URLs that we grabbed earlier.
In the left sidebar under Tools, select Redirection.
Under Source URL enter the old post URL. Under Target URL, enter the new post URL (with the prefix).
Then, click Add Redirect.
Be sure to open the source URL to make sure it automatically redirects to the target URL. You can also find the redirect in the Redirection list and click “Check Redirect”.
Repeat this for all posts!
Conclusion
We hope that your blog prefix is working well after following this post!
If you have any questions or need help managing your WordPress website, please reach out to us!
Jonathan is a WordPress expert with 10+ years of experience building and managing websites. He owns WPCharger, a service business that specializes in managing WordPress websites for small and midsize businesses.