我的 htaccess 规则中的粗心错误


Careless mistake in my htaccess rule

我正在编写一个.htaccess规则

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

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

问题是当我打印$col1它的显示索引时.php而不是测试我。我做错了什么?

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

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