301重定向 - 重定向父级但不是子级

use*_*735 1 .htaccess mod-rewrite redirect

我如何重新指导父目录而不是孩子?请参阅下面的具体问题.所有和任何帮助表示赞赏!

家长 -

redirect 301 /community/whats-happening http://www.stapletondenver.com/whats-happening/  
Run Code Online (Sandbox Code Playgroud)
  • 重定向父目录

孩子 -

redirect 301 /community/whats-happening/celebrating-halloween-stapleton http://www.stapletondenver.com/whats-happening/celebrating-halloween-in-stapleton/  
Run Code Online (Sandbox Code Playgroud)

我尝试过其他一些选择但没有成功.见下文:

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

RewriteRule ^community/whats-happening/(.*)$ /whats-happening/$1 [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/$1 [R=301,L]
RewriteRule ^community/whats-happening/(.*)/(.*)/? http://stapletondenver.com/whats-happening/$1/ [R=301,L]
Run Code Online (Sandbox Code Playgroud)

Jon*_*Lin 6

由于您的第一次重定向,这种情况正在发生.该Redirect指令将所有子目录和文件重定向到,因此:

Redirect 301 /abcd http://domain.com/xyz
Run Code Online (Sandbox Code Playgroud)

手段

  • /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/
Run Code Online (Sandbox Code Playgroud)