redirect wordpress child pages to their parent page

久未见 提交于 2021-02-11 18:03:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!