2014-07-15 36 views
1

我很好奇,如果有人能夠教育我更好地理解爲什麼以下不起作用的命令。301重定向的順序?

當我首先爲/ contact重定向時,位置頁面無法正確重定向。

Redirect 301 /contact http://www.example.com/contact-us 

Redirect 301 /index.php/contact/location1 http://www.example.com/contact-us/location1 

Redirect 301 /index.php/contact/location2 http://www.example.com/contact-us/location1 

當我把它放在位置後面時,它們正常工作。爲什麼是這樣?

Redirect 301 /index.php/contact/location1 http://www.example.com/contact-us/location1 

Redirect 301 /index.php/contact/location2 http://www.example.com/contact-us/location1 

Redirect 301 /contact http://www.example.com/contact-us 

回答

1

這是因爲其他2個URL也有/contact在其中。

使用RedirectMatch指令總是更好,它具有使用正則表達式的能力,因此您可以完全匹配您需要的東西。

使用RedirectMatch指令下也將工作:

RedirectMatch 301 ^/contact/?$ http://www.example.com/contact-us 

RedirectMatch 301 ^/index\.php/contact/location1/?$ http://www.example.com/contact-us/location1 

RedirectMatch 301 ^/index\.php/contact/location2/?$ http://www.example.com/contact-us/location1 
+0

太謝謝你了。這現在非常有意義! – Myoji

+0

不客氣,很高興它解決了。 – anubhava