How to change your WordPress Permalink Structure

Today I sat down to modify the permalink structure for this web site. The URLs for this blog used to include the /YYYY/MM/ date parts in them, and until recently, I never really gave them much thought except to think that it was sometimes interesting.

But lately I have come to realise that having the year and month numbers in the URL is probably not such a useful idea for a tiny site like mine, especially also considering the fact that I post maybe only once or twice a month.

The more I thought about it, the more it became clear that changing this setting was not going to be as complicated as it seemed to me initially, or even such a great big deal. So today, I just jumped right into it.

What GIDBlog.com blog post URLs looked liked in the past (note the year and month numbers in the URLs):


https://www.gidblog.com/2000/12/compress-your-web-page/


https://www.gidblog.com/2001/01/hacking-hotmail-not/


https://www.gidblog.com/2003/03/refresh-redirect-using-php

What they look like today:


https://www.gidblog.com/compress-your-web-page/


https://www.gidblog.com/hacking-hotmail-not/


https://www.gidblog.com/refresh-redirect-using-php/

Changing WordPress Permalink Structure and 301 Redirection

Modify WordPress Permalink Structure

The first step is to modify the WordPress Permalink Structure setting in your WordPress dashboard. Go to your WordPress dashboard and find Settings > Permalinks, and select the “Post name” option.

Remember to save your changes!

Screenshot of WordPress Permalink Structure setting page.

Screenshot of WordPress Permalink Structure setting page.

Redirect your old permalinks to the new ones

Next, you will want to know how to redirect old links after changing the permalink structure of your blog.

You would want to manage (correctly and properly) all that traffic already coming in to your web site using the old URLs. You will do that by returning a 301 Moved Permanently HTTP response status code, including the new URL to any client, including Googlebot and other popular search engine spiders, requesting the page with the old URL.

The good news is this: You will only have to insert a couple of lines inside one file, upload it to your web server, and that is all you have to do to accomplish this seemingly huge task!

Modify the .htaccess file

You will usually find a .htaccess file in your WordPress folder and it will commonly look like this:


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

All you have to do is insert the following lines in between line no. 5 and 6 (above).


	# Handle change in the permalink setting
	RewriteRule ^\d{4}/\d{2}/(.+) $1 [R=301,L]

After inserting those 2 lines, your .htaccess file should now look a bit like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

	# Handle change in the permalink setting
	RewriteRule ^\d{4}/\d{2}/(.+) $1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Save the changes and upload this modified .htaccess file to your web server.

Don’t forget to remember to restart httpd i.e. the web server!

Do not hesitate to ask below in the comments, if your permalink changes do not match the examples in this post and I will try to assist you when (and if) I can.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>