I've change permalink of my wordpress site from
/%category%/%postname%/
to
%postname%
I've tested this code:
RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ site.com/$4
RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/]+)/$ site.com/$3
and good work for redirect posts but this code redirect categories address too and show 404 not found page.
I need to only redirect old posts address to new address. Is it possible that only the posts be redirect?
Example:
site.com\cat1\subcat\post
redirect to:
site.com\post (no problem)
my site Categories in two or three level
two level not have problem but three level:
site.com\cat1\subcat\subcat2
(Categories should not be redirect)
but redirect to:
site.com\subcat2 (and Error 404 Not Found)
You can probably do this with PHP.
if (!empty($_POST)) {
header('Location: ' . $url, true, 301);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.