为什么这个.htaccess代码会进行持续重定向


Why does this .htaccess code do a constant redirect?

标题解释了大部分内容。我使用的是WAMP。我有一个.htaccess文件,其中包含以下内容:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$
RewriteRule (.*)  /?uri=%{REQUEST_URI}

和一个包含以下内容的index.php:

<?php
print_r($_GET)
?>

此外,我得到以下apache_error.log错误:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

如果你对我正在做的事情感到困惑,我正在尝试制作一个cms,其中index.php处理所有其他页面并自行处理(我刚刚开始)。

它正在进行无限循环,因为即使重写为/?uri-...%{REQUEST_URI}也保持为空

您应该检查%{QUERY_SRING}来检查是否存在查询字符串。

RewriteEngine On
RewriteCond %{QUERY_STRING} !(^|&)uri= [NC]
RewriteRule ^ ?uri=%{REQUEST_URI} [L,QSA]