1

我正在编写一个 .htaccess 规则作为

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

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

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

4

1 回答 1

3

This is because the rewrite engine loops, try adding some conditions:

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

or even:

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

When the rewrite engine loops, the (.+) part of your regex ends up matching index.php, and thus col1= turns into index.php.

于 2013-10-22T13:47:37.317 回答