TIMMGuru

htaccess redirect Year/Month to Post Name

without comments

I have wanted to change this WordPress blog URL from year/month/file-name.html to just file-name.html. I could simply change the setting in the WordPress permalink option. But that is not 100% right because all the older posts will lose the inbound link. That’s why I have to use a htaccess 301 redirect to make sure the old URLs are properly redirect to the new URL structure.

After some googling, the solution is simpler than I thought!

Add these lines to your .htaccess file:

# change year/month/file-name.html permalinks to file-name.html only
RedirectMatch 301 ^/([0-9]+)/([0-9]+)/(.*)$ http://www.timmguru.com/$3

Now this blog has shorter URLs and older inbounds will continue to pass on the link juice.

If you were using Year/Month/Day/file-name then the codes should be:

# change year/month/day/file-name permalinks to file-name only
RedirectMatch 301 ^/([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://www.timmguru.com/$4

Leave a comment