Php 多个MOD重写规则
我想做什么 我想重定向: www.example.com/home/place到www.example.com/index.php?location=place www.example.com/home至www.example.com/index.php。 我所做的 在.htaccess中,我有以下行: 重写规则^home/[^/]*$index.php?位置=$1[L] 这是第1部分。但是,有了这一点,第2部分就不起作用了。但是,如果我在上面之前写下: 重写规则^home index.php[L] 那么第2部分就行了,但第1部分不行 长话短说,我不知道如何启用这两个规则。这有可能吗?如果有,怎么可能?问题在于Php 多个MOD重写规则,php,.htaccess,mod-rewrite,url-rewriting,Php,.htaccess,Mod Rewrite,Url Rewriting,我想做什么 我想重定向: www.example.com/home/place到www.example.com/index.php?location=place www.example.com/home至www.example.com/index.php。 我所做的 在.htaccess中,我有以下行: 重写规则^home/[^/]*$index.php?位置=$1[L] 这是第1部分。但是,有了这一点,第2部分就不起作用了。但是,如果我在上面之前写下: 重写规则^home index.php[
RewriteRule ^home index.php [L]
将匹配这两个示例,因为它们都以home开头。请尝试以下操作:
RewriteRule ^home/?$ index.php [L]
这将匹配/home和/home/但不匹配/home/foo。您的第一条规则将参数作为可选参数,因为您使用的是*而不是+: 此外,第二条规则中没有$表示URI的结尾:
RewriteRule ^home/?$ index.php [L]
现在,规则可以是您想要的任何顺序
RewriteRule ^home/?$ index.php [L]