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
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%
.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: