The Right Way To Change Your WordPress Permalink

When I changed my WordPress permalinks, I started getting many 404 errors from Google Webmaster Tools. This is because Google still had the old permalink of this blog. I changed my permalink from:

/%category%/%post_name%/%id%

to just:

%post_name%

since it is a more search-engine-friendly URL.

I was getting around 400 pages showing 404 errors. After looking for solutions on the web, what I needed was to redirect all old URLs to the new permalink. I found the smart way to do this using htaccess. Thanks to Yoast.com for making a very handy script to generate the 301 redirects in htaccess. You can generate it here.

And here is my htaccess sample:

RewriteEngine On
RewriteBase /
RedirectMatch 301 ^/([^/]+)/([^/]+)/(d+)/$ http://www.ivankristianto.com/$2
RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/]+)/(d+)/$ http://www.ivankristianto.com/$3
RedirectMatch 301 ^/(d+)/(d+)/([^/]+)/$ http://www.ivankristianto.com/$3

Now all my old permalinks will automatically redirect to new permalinks with that simple trick.

If you like this post and would like to give feedback, please let me know in the comments below.