Redirect Ugly Permalink to Postname

by Hiroshi on November 21, 2008

in Hacks, WordPress

Most of the blogs, even popular blogs have their permalink structure like:
https://www.yourblog.com/year/month/day/post-name/

WordPress Offers following permalink structures:

https://www.yourblog.com/?p=123 (Default)
https://www.yourblog.com/2008/11/10/sample-post/ (year/month/day/postname)
https://www.yourblog.com/2008/11/sample-post/ (year/month/postname)
https://www.yourblog.com/archives/123 (numeric)
and custom permalink structure

The recommended one by SEO experts is following:
https://www.yourblog.com/sample-post/
Which can be achieved by putting /%postname%/ in custom permalink box from your admin area under permalinks.

Many bloggers will not switch to recommended permalink because they have got backlinks for their old permalink. If you are still using the ugly /%year%/%month%/%day%/%postname%/ permalink structure, you should be interested to know how you can switch to the elegant /%postname%/ structure without loosing any backlink, using a simple .htaccess redirection.

The first thing to do is to change permalink structure from your admin area.
Go to Permalinks
Select custom
Fill out the field with /%postname%/

https://www.yourblog.com/post-name

Now we have got to redirect all backlinks using the old permalinks structure to the new permalink structure. To do so, you’ll have to edit the .htaccess file, located in WordPress installation root directory.

Paste the following line in your .htaccess:

RedirectMatch 301 /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ https://www.domain.com/$4

Congrats! You just changed your permalinks structure without loosing any backlinks! Cheers…

Related Posts

Previous post:

Next post: