Php Symfony导致mod_rewrite重定向错误
我已经在CentOS 7虚拟机上运行了symfony 2.8。现在,当我尝试转到我的站点时,我得到一个内部服务器错误。当我检查日志时,它说:Php Symfony导致mod_rewrite重定向错误,php,.htaccess,mod-rewrite,apache2,symfony-2.8,Php,.htaccess,Mod Rewrite,Apache2,Symfony 2.8,我已经在CentOS 7虚拟机上运行了symfony 2.8。现在,当我尝试转到我的站点时,我得到一个内部服务器错误。当我检查日志时,它说: Request exceeded the limit of 10 internal redirects due to probable configuration error 我将apache中的LogLevel设置为trace3,看起来app.php周围有一大堆重定向。我不知道发生了什么事。我还没有修改symfony附带的.htaccess文件。以下是
Request exceeded the limit of 10 internal redirects due to probable configuration error
我将apache中的LogLevel
设置为trace3,看起来app.php周围有一大堆重定向。我不知道发生了什么事。我还没有修改symfony附带的.htaccess文件。以下是.htaccess文件中的mod_重写块:
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by apache
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
重新启动发动机
#自动确定RewriteBase并将其设置为环境变量。
#如果您使用Apache别名进行大规模虚拟托管或安装
#在子目录中的项目中,将在基本路径前面加上前缀,以允许正确的
#解析app.php文件并重定向到正确的URI。会的
#也可以在没有路径前缀的环境中工作,提供一个安全的单一大小
#适用于所有解决方案。但是,在这种情况下,您不需要它,您可以进行评论
#以下两条线路可消除开销。
RewriteCond%{REQUEST_URI}:$1^(/.+)/(.*):\2$
重写规则^(.*)-[E=基:%1]
#设置apache删除的HTTP_授权头
RewriteCond%{HTTP:Authorization}。
重写规则。*-[E=HTTP\U授权:%{HTTP:AUTHORIZATION}]
#重定向到不带前端控制器的URI以防止重复内容
#(带或不带“/app.php”)。仅在初始路径上执行此重定向
#由Apache重写,而不是在后续周期中重写。否则我们会被解雇
#无休止的重定向循环(请求->重写到前端控制器->
#重定向->请求->…)。
#所以,如果你得到一个“太多重定向”错误或你总是得到重定向
#因为您的Apache没有公开重定向的状态,所以无法访问起始页
#环境变量,您有两种选择:
#-通过注释以下两行或两行禁用此功能
#-使用Apache>=2.3.9,用结束标志替换所有L标志,并删除
#第二步(最佳解决方案)
RewriteCond%{ENV:REDIRECT_STATUS}^$
重写规则^app\.php(/(.*)|$)%{ENV:BASE}/$2[R=301,L]
#如果请求的文件名存在,只需提供它即可。
#我们只想让Apache服务于文件,而不是目录。
RewriteCond%{REQUEST_FILENAME}-f
重写规则[L]
#将所有其他查询重写到前端控制器。
重写规则.?%{ENV:BASE}/app.php[L]
这是我的httpd.conf(不要担心任何安全问题。这是一个仅用于开发目的的本地安装)
#安全
服务器令牌操作系统
服务器签名
可追溯
服务器名“dev.indygaa.vm”
ServerRoot“/etc/httpd”
PidFile run/httpd.pid
超时120
拒之门外
MaxKeepAliveRequests 100
暂停15分钟
用户apache
组apache
AccessFileName.htaccess
要求全部拒绝
选项如下符号链接
允许超越所有
主机名查询
ErrorLog“/var/log/httpd/error\u log”
日志级别跟踪3
在上启用SendFile
#听80
包括“/etc/httpd/conf.d/*.load”
包括“/etc/httpd/conf/ports.conf”
日志格式“%h%l%u%t\%r\”%>s%b\“%%{Referer}i\\\“%%{User Agent}i\\”组合
日志格式“%h%l%u%t\%r\”%>s%b”通用
日志格式“%{Referer}i->%U”Referer
日志格式“%{User agent}i”代理
包括可选“/etc/httpd/conf.d/*.conf”
我看不出这种重定向一直在哪里发生。我缺少什么?将您上次的
重写规则更改为:
RewriteRule !/app\.php$ %{ENV:BASE}/app.php [L,NC]
将上一次重写规则更改为:
RewriteRule !/app\.php$ %{ENV:BASE}/app.php [L,NC]
这导致app.php找不到404,这意味着%{ENV:BASE}/app.php
(即当前目录中的app.php
)不存在。确定。我怀疑您可能没有尝试从正确的文档根中提取。我如何知道它试图从何处提取app.php?如果app.php
与.htaccess
存在于同一文件夹中,那么您可以尝试:重写规则^app\.php$app.php[L,NC]
好的,那么最好使用正确的已知路径,而不是导致app.php找不到404的%{ENV:BASE}
,这意味着%{ENV:BASE}/app.php
(即当前目录中的app.php
)不存在。好的。我怀疑您可能没有尝试从正确的文档根中提取。我如何知道它试图从何处提取app.php?如果app.php
与.htaccess
存在于同一文件夹中,那么您可以尝试:重写规则^app\.php$app.php[L,NC]
oh ok,那么最好使用正确的已知路径,而不是%{ENV:BASE}