我的htaccess规则中的粗心错误

时间:2013-10-22 13:42:37

标签: php apache .htaccess mod-rewrite

我正在编写.htaccess规则

RewriteRule ^questions\/interview\/list\/(.+)$ questions\/interview\/list\/index.php?col1=$1

因此,当我调用网址questions/interview/list/testme时,它会重定向到index.php

问题是当我打印$col1时显示index.php而不是testme。我做错了什么?

1 个答案:

答案 0 :(得分:3)

这是因为重写引擎循环,尝试添加一些条件:

RewriteCond %{REQUEST_URI} !index\.php$
RewriteRule ^questions/interview/list/(.+)$ questions/interview/list/index.php?col1=$1 [L]

甚至:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^questions/interview/list/(.+)$ questions/interview/list/index.php?col1=$1 [L]

当重写引擎循环时,正则表达式的(.+)部分最终与index.php匹配,因此col1=变为index.php