2014-01-05 102 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] 

现在规则可以以任何你想要的顺序。