我如何重新指导父目录而不是儿童?请参阅下面的具体问题。所有和任何帮助表示赞赏!
家长 -
redirect 301 /community/whats-happening http://www.stapletondenver.com/whats-happening/
儿童 -
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/$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]
答案 0 :(得分:6)
由于您的第一次重定向,这种情况正在发生。 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/