301 重定向 - 重定向 parent 但不是 children

301 redirect - Redirect parent but not it's children

我如何处理 re-directing 一个 parent 目录而不是 children?请参阅下面我的具体问题。感谢所有帮助!

Parent -

redirect 301 /community/whats-happening http://www.stapletondenver.com/whats-happening/  

Child -

redirect 301 /community/whats-happening/celebrating-halloween-stapleton http://www.stapletondenver.com/whats-happening/celebrating-halloween-in-stapleton/  

我尝试了一些其他选项,但都没有成功。见下文:

RewriteRule  ^community/whats-happening/. /whats-happening/ [R=301,L]

RewriteRule ^community/whats-happening/(.*)$ /whats-happening/ [R=301,NC,L]

RewriteRule ^/?community/whats-happening/?$ http://www.stapletondenver.com/whats-happening/ [R=301]

RewriteRule ^community/whats-happening/(.*) http://stapletondenver.com/whats-happening/ [R=301,L]
RewriteRule ^community/whats-happening/(.*)/(.*)/? http://stapletondenver.com/whats-happening// [R=301,L]

发生这种情况是因为您的第一次重定向。 Redirect 指令将所有子目录和文件重定向到:

Redirect 301 /abcd http://domain.com/xyz

表示

  • /abcd/ -> http://domain.com/xyz/
  • /abcd/1234/ -> http://domain.com/xyz/1234/
  • /abcd/1234/z.html -> http://domain.com/xyz/1234/z.html

等等

如果您只想重定向父目录,请使用正则表达式和带有 $ 结束字符的 RedirectMatch

RedirectMatch 301 ^/community/whats-happening/?$ http://www.stapletondenver.com/whats-happening/  
RedirectMatch 301 ^/community/whats-happening/celebrating-halloween-stapleton/?$ http://www.stapletondenver.com/whats-happening/celebrating-halloween-in-stapleton/