【问题标题】:Loop Redirect - .htaccess issue循环重定向 - .htaccess 问题
【发布时间】:2025-11-25 00:45:02
【问题描述】:

我正在尝试解决本地主机上的问题。

我有一个使用以下 .htaccess 文件的脚本

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /agg/
RewriteCond %{HTTP_HOST} ^localhost  
RewriteRule ^(.*)$ http://localhost/agg/$1 [R=permanent,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /agg/index.php [L]
</IfModule>

“agg”是本地主机上存储文件的文件夹。

(完整路径:C:\wamp\www\agg)

当我尝试访问 http://localhost/agg/ 时,它给了我“此网页存在重定向循环”错误。

apache rewrite_module 开启,php 版本为 5.4.12

还有一个名为“config.php”的文件,其中包含以下代码:

<?php
$siteurl = "http://localhost";

//.... etc
?>

任何帮助将不胜感激。

【问题讨论】:

    标签: php .htaccess mod-rewrite redirect rewrite


    【解决方案1】:

    您的第一条规则是导致此循环的罪魁祸首。有这个代码在/agg/.htaccess:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /agg/
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    </IfModule>
    

    【讨论】: