2015-01-08 58 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