2014-01-05 99 views
-1

我試圖做多種MOD重寫規則

我想重定向:

  1. www.example.com/home/placewww.example.com/index.php?location=place
  2. www.example.com/homewww.example.com/index.php

我所做的

.htaccess,我有以下行:

RewriteRule ^home/([^/]*)$ index.php?location=$1 [L]

這確實一部分。然而,與此到位,第2部分做不行。不過,如果我寫這上面之前:

RewriteRule ^home index.php [L]

則第2級部分的作品,但第1部分沒有。

長話短說,我無法弄清楚如何啓用這兩個規則。這是可能的,如果是的話,如何?

回答

1

的問題是,

RewriteRule ^home index.php [L] 

將匹配這兩個例子中,因爲它們都與「家」開始。請嘗試以下操作:

RewriteRule ^home/?$ index.php [L] 

這將匹配/ home和/ home /而不是/ home/foo。

1

你的第一個規則具有參數爲「可選」,因爲你正在使用的*代替+

RewriteRule ^home/([^/]+)$ index.php?location=$1 [L] 

此外,您沒有$在你的第二個規則,表示結束的網址:

RewriteRule ^home/?$ index.php [L] 

現在規則可以以任何你想要的順序。