在本地主机的 xampp 中启用重写模式



我使用的是Windows 7 64位(也许这并不重要),并且安装了xampp。在我的htdocs/目录中,我有多个项目。现在,对于其中一个(比如htdocs/test/),我创建了名为"example"的vhost。这工作正常...在 dir/test/里面,我有带有以下代码的 .htaccess 文件:

RewriteEngine on
RewriteBase /test
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*).(js|gif|jpeg|jpg|png)$
RewriteRule . index.php

在这里,我想将所有流量重定向到我的index.php页面,因为我在这里使用了一些从索引页面开始的整个项目的系统。在httpd.conf,我启用了rewrite_module和内部

<Directory "C:/Program Files/xampp/htdocs">

我已将AllowOverride指令更改为All .

现在,正如我所说,当我尝试使用创建的 vhost"示例"访问我的项目时,这工作正常。但是当我尝试访问htdocs dir中的其他项目时,我收到内部服务器错误(HTTP 500)和日志文件中的以下消息:

[Thu Nov 15 11:07:12 2012] [error] [client 127.0.0.1] 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.

另外,如果我输入 URL 127.0.0.1localhost,我会用"示例"vhost 定义我的项目......这非常令人困惑,有人可以帮忙吗?

听起来您的根目录和子目录 htaccess 文件存在冲突。从根 htaccess 文件中排除子目录处理,并确保使用 [L] ast 规则指令。

根 HTACCESS - 排除"test"子目录,使用 ast 规则指令[L]

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*).(js|gif|jpeg|jpg|png)$
# exclude the "test" subdirectory
RewriteCond %{REQUEST_URI} !^(test)/?
# add [L]
RewriteRule . index.php [L]

"测试"子目录 HTACCESS - 使用 ast 规则指令[L]

RewriteEngine on
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*).(js|gif|jpeg|jpg|png)$
# add [L]
RewriteRule . index.php [L]

最新更新