3

A few years ago this was the permalink structure I had for my blog:

/%year%/%category%/%postname%.html

I changed these permalinks last year to this:

/%category%/%postname%/%post_id%/

A plugin that goes by the name Permalinks Redirect was used, and it worked pretty well to permanently redirect older URLs to newer ones. However, after a recent WordPress update to 3.4.1 version, I noticed the older permalinks are no longer redirecting.

The problem is not with the plugin -- I have spent 2 days dabbling with every redirect plugin I could find. After a bit of Googling, I figured out the problem is with WordPress 3.4, and a bug has been already submitted.

All the older URLs are throwing out 404 errors, which is frustrating. I'd really appreciate if there's a HTACCESS redirect code, or MOD_REWRITE code (the site is using nginx, if that helps) that could be posted here.

I have very little knowledge about redirection.

2 Answers 2

1

You can try this but not 100% sure it will work since the post_id is not in the original permalink structure.

RedirectMatch 301 ^/([0-9]{4})/([^/]+)/([^/]+).html$ http://domain.com/$2/$3/

1
  • Chris, thanks a lot! The code almost works -- yes, there is no post_ID in the original permalink, and the URLs do not redirect properly. I tweaked the code a bit: RedirectMatch 301 ^/([0-9]{4})/([^/]+)/([^/]+).html$ domain.com/?p=$1 This redirects to another random post, although this is not what I need. Adding (\d+) to the HTML structure solves the problem, but our older permalink structure doesn't have post_ID as you have already mentioned. What do you think is the best solution? How can we inject post_ID in these URLs?
    – Sid
    Jul 4, 2012 at 13:56
-1

First of all how are you possibly using mod_rewrite rules in an nginx powered site? That's a neat trick I'd like to learn :)

Anyway if you are using Apache try this:

RedirectMatch 301 ^/([0-9]{4})/([^/]+)/([^/]+).html$ example.com/?name=$3

The above uses the post's slug instead of the ID (which is missing in the old URLs). WP should redirect again to your SE friendly URLs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.