.htaccess issues



我有一个页面做两件事:

当用户点击这个链接时:http://www.example.com/whatever_200/index.html/?id=4它实际上是由http://www.example.com/search/profile-condo.php?id=4

然而,我也想为巴西人做以下事情www.example.com/br/whatever_200/index.html/? id = 4www.example.com/br/search/profile-condo.php ? id = 4

以下内容适用于英文版本:

addhandler x-httpd-php5 .html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/index.html$ /search/profile-condo.php?name=$1&%{QUERY_STRING} [L,QSA]

但是当我加上

RewriteRule ^(.*)/br/^(.*)/index.html$ /br/search/profile-condo.php?name=$1&%{QUERY_STRING} [L,QSA]

它不工作

我做错了什么?

你的规则有三个问题。

首先是规则顺序。第一个规则将匹配任何以/index.html结尾的内容,它将执行重定向。它被(正确地)标记为最终规则(L标志)。正因为如此,第二条规则永远不会被执行。如果在通用规则之前添加br规则,将首先对其进行测试,如果匹配,则进行重定向。

第二个问题是第二条规则上的正则表达式。它在表达式的一半包含一个旋转的^。旋指的是字符串的开头,它显然不会出现在字符串的中间。移除旋流器可以解决这个问题。

第三个问题是您允许在url的/br/部分之前使用字符(通过在表达式中使用(.*))。根据你的描述,你实际上并不需要这个。

总结:

addhandler x-httpd-php5 .html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/br/(.*)/index.html$ /br/search/profile-condo.php?name=$1&%{QUERY_STRING} [L,QSA]
RewriteRule ^(.*)/index.html$ /search/profile-condo.php?name=$1&%{QUERY_STRING} [L,QSA]

最新更新