skip to Main Content

Hi i’m trying to add a redirect regex to my .htaccess that redirect

from /%year%/%monthnum%/%postname%.html to /%category%/%postname%/%post_id%/

Yaost helper gave me this

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

i’m not an expert but i think it doesn’t match my structure

Also the permalink is not an option migration from blogger to wordpress already done long ago and permalink won’t do the trick and all the upper links are giving 404

2

Answers


  1. It matches the URL you are wanting to redirect from. However, the redirect target is incorrect, as it will redirect to /%postname%, not /%category%/%postname%/%post_id%/.

    But therein lies a problem, it’s not possible to redirect to /%category%/%postname%/%post_id%/ using .htaccess since %catgeory% and %post_id% are not present in the source URL.

    You will need to do this using a redirection plugin in WordPress itself, since only WP knows this information. WP would need to lookup the %category% and %post_id% from its database using %year%, %monthnum% and/or %postname%.

    Login or Signup to reply.
  2. There is no way take make this change using regex in .htaccess. To be able to redirect to the new URL you need the %category% and the %post_id% for each URL, neither of which are available in the old URL. You can’t use regular expressions to parse the old URL and redirect to the new URL because the information to do so isn’t available to the regex.

    To implement this change you will need a totally different approach like one of the following:

    • Install a redirect plugin to WordPress such as one of the ones suggested in How To Change A WordPress Permalink.
    • Create a list of all the URLs and create a mapping between the old and new URLs to redirect each individually. For a long list, you would want to use something like Apache’s RewriteMap functionality.
    • Rewrite the old style URLs to a custom handler and program it to look up the new URLs from the WordPress database.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search