问题
I have a glossary page in my site with child pages like this:
http://my-domain.com/glossay/a/
http://my-domain.com/glossay/b/
http://my-domain.com/glossay/c/
...
& every item in glossary has it's own child page based on alphabet like this:
http://my-domain.com/glossay/a/abandon/
http://my-domain.com/glossay/a/art/
http://my-domain.com/glossay/b/bee/
...
I need a redirection rule to redirect users from items child page, to their parent page based on their first word. for example:
http://my-domain.com/glossay/a/abandon/
Redirects To:
http://my-domain.com/glossay/a/
http://my-domain.com/glossay/b/bee/
Redirect to:
http://my-domain.com/glossay/b/
thanks.
回答1:
The following .htaccess rule should do the trick:
RewriteRule ^glossay/([a-zA-z])/.+$ /glossay/$1 [L,R=302]
Basically everything that's after the letter gets truncated and the user is redirected to the parent letter. Note that this rule will also redirect children of children, if any (e.g. /glossay/a/another/children will be also redirected to /glossay/a)
来源:https://stackoverflow.com/questions/29393131/redirect-wordpress-child-pages-to-their-parent-page