.htaccess mod_rewrite在url中多次显示apache2 documentroot

.htaccess mod_rewrite在url中多次显示apache2 documentroot,.htaccess,redirect,mod-rewrite,webserver,apache2,.htaccess,Redirect,Mod Rewrite,Webserver,Apache2,我现在正在做一个小PHP项目 为此,创建了一个简单的router类,该类接受GET参数的值,将其拆分并调用请求的类和方法 我的.htaccess文件应该重写请求的url,以便调用 应该重定向到哪个位置 到目前为止还不错。这将使用以下.htaccess文件: DirectoryIndex index.php RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d Rewri

我现在正在做一个小PHP项目

为此,创建了一个简单的router类,该类接受GET参数的值,将其拆分并调用请求的类和方法

我的.htaccess文件应该重写请求的url,以便调用

应该重定向到哪个位置

到目前为止还不错。这将使用以下.htaccess文件:

DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1 [QSA]
但是现在,如果我试图访问基本URL

我被重定向到

我无法解释我自己

老实说,直到现在,我才对mod_rewrite做了很多工作,但这种行为对我来说很奇怪

希望有人能帮助我

谢谢各位

编辑2017-01-15 看起来它与htaccess文件无关

起初我用这个测试了我的文件,它看起来像我想要的那样工作

我试图删除htaccess文件,但仍然存在相同的问题。 所以我假设它是由apache2 Web服务器引起的

我将虚拟主机中的日志级别设置为调试,并从中获得以下信息:

[Sun Jan 15 09:33:41.684274 2017][authz_core:debug][pid 2183]mod_authz_core.c(809):[client 10.0.2.2:49743]AH01626:请求所有授予的授权结果:授予

[Sun Jan 15 09:33:41.684355 2017][authz_core:debug][pid 2183]mod_authz_core.c(809):[client 10.0.2.2:49743]AH01626:授权结果:已授予

[Sun Jan 15 09:33:41.684445 2017][core:info][pid 2183][client 10.0.2.2:49743]AH00128:文件不存在:/var/www/public/var/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/。phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.php


这对我父亲来说毫无意义。虚拟主机的我的配置文件不包含重写规则。

导致此问题的原因是每次访问本地主机时它都会循环。 尝试通过添加[L]标志来停止此循环,如以下代码所示:
RewriteRule^(.*)$/index.php?路由=$1[L,QSA]

更新 我已经创建了一个在我这边起作用的示例:

我创建了一个带有页面参数的主索引页面。因此,像
index.php?class=software
这样的链接将带您进入软件页面,而到
index.php?class=test
的链接将带您进入测试页面。使用mod_,rewrite是将用户从class/software/悄悄地重定向到
index.php?class=software

以下是需要进入.htaccess文件才能完成的内容:

重新编写引擎打开
重写规则^class/([^/\.]+)/?$index.php?class=$1[L]


另外,它在访问index.php页面时不会循环。

导致此问题的原因是每次访问本地主机时它都会循环。 尝试通过添加[L]标志来停止此循环,如以下代码所示:
RewriteRule^(.*)$/index.php?路由=$1[L,QSA]

更新 我已经创建了一个在我这边起作用的示例:

我创建了一个带有页面参数的主索引页面。因此,像
index.php?class=software
这样的链接将带您进入软件页面,而到
index.php?class=test
的链接将带您进入测试页面。使用mod_,rewrite是将用户从class/software/悄悄地重定向到
index.php?class=software

以下是需要进入.htaccess文件才能完成的内容:

重新编写引擎打开
重写规则^class/([^/\.]+)/?$index.php?class=$1[L]


另外,它在访问index.php页面时不会循环。

谢谢您的回答。遗憾的是,它没有改变任何事情。仍然是相同的行为。我们使用^(.*)处理所有事情,这可能会导致此循环,请尝试使用
RewriteOptions maxredirect=1
对其进行限制,并添加一个选项
Options+FollowSymlinks
,请告诉我。我尝试过了。但还是没有变化。但现在我的apache2错误日志显示:[Sat Jan 14 20:13:25.288749 2017][rewrite:warn][pid 3143]AH00664:RewriteOptions:MaxRedirects选项已被删除,以支持global LimitInternalRecursion指令,并将被忽略。我添加了选项+FollowSymlinks。在与LimitInternalRecursion交换MaxRedirects后,我遇到了一个500内部服务器错误和以下消息:[Sat Jan 14 20:23:05.145732 2017][core:alert][pid 3143][client 10.0.2.2:63417]/var/www/public/.htaccess:RewriteOptions:unknown option'LimitInternalRecursion=1'对不起,我的错了,在.htaccess文件中,您应该将
Options+FollowSymlinks
RewriteRule^(.*)/index.php?route=$1[L,QSA]
放在vhosts文件中,您可以尝试将
LimitInternalRecursion 1
放在vhosts文件中。谢谢您的回答。遗憾的是,它没有改变任何事情。仍然是相同的行为。我们使用^(.*)处理所有事情,这可能会导致此循环,请尝试使用
RewriteOptions maxredirect=1
对其进行限制,并添加一个选项
Options+FollowSymlinks
,请告诉我。我尝试过了。但还是没有变化。但现在我的apache2错误日志显示:[Sat Jan 14 20:13:25.288749 2017][rewrite:warn][pid 3143]AH00664:RewriteOptions:MaxRedirects选项已被删除,以支持global LimitInternalRecursion指令,并将被忽略。我添加了选项+FollowSymlinks。在与LimitInternalRecursion交换MaxRedirects后,我发现一个500内部服务器错误和以下消息:[Sat Jan 14 20:23:05.145732 2017][core:alert][pid 3143][client 10.0.2.2:63417]/var/www/public/.htaccess:Rew