2015-01-08 45 views
1

我该如何着手重新指导父目录而不是子级?看到我下面的具体问题。所有和任何帮助表示赞赏!301重定向 - 重定向父级,但不是子级

家长 -

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] 

回答

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/ 
+0

非常感谢您的详细解释,即伟大工程!重定向总是让我有所有的变化。在这里学到了很多,再次感谢! – user2105735