Symfony2 和 html5boilerplate 重定向规则的 400 错误请求
我最近转向使用 Symfony2 PHP 框架,并希望从一开始就包含 html5boilerplate 的所有强大功能,但是在合并两者的 .htaccess 文件时遇到了一些问题。
前三名来自样板;从 www.example.com 重定向到 example.com,从 example.com/test 重定向到 example.com/test/,并限制对任何以 . (例如.git)。
最后是Symfony2对前端控制器的重写。如果没有其他重定向发生,我希望能够访问它(因此 example.com/hello/ 应该到达它)。
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ /$1/ [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteRule "(^|/)\." - [F]
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
如果最后一次重写被注释,Apache 将返回 400 Bad Request,我不太确定为什么。重定向设置为外部(R = 301),因此它应该重新评估,并访问 app.php 一个。
重写也已设置为打开。
任何建议都会很棒,不需要太多重写 buff =(
I've recently moved over to using the Symfony2 PHP framework, and wanted to include all of the awesomeness of the html5boilerplate from the outset, however having a few problems with merging the .htaccess files for both.
The top three are from boilerplate; redirecting from www.example.com to example.com, example.com/test to example.com/test/, and restricting access to any folders prepended with a . (.git, for example).
The final is Symfony2's rewrite for the front end controller. I'd like this to be accessed if no other redirects happen (so example.com/hello/ should reach it).
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ /$1/ [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteRule "(^|/)\." - [F]
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
If the last rewrite is commented, Apache returns a 400 Bad Request, and I'm not quite sure why.. The redirect are set to external (R=301) so it should re-evaluate, and get to the app.php one.
Rewrite is already set to on as well.
Any suggestions would be great, not much of a rewrite buff =(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试使用你的配置,没有问题到达我的 Symfony2 设置。
尝试将您的请求重定向到
app_dev.php
而不是app.php
,以便您可以跟踪真正的错误。或者我误解了你的问题?
I tried with your config and had no problem to reach my Symfony2 setup.
Try to redirect your requests to
app_dev.php
instead ofapp.php
so you can track the real error.Or am I missunderstanding your question?
我不是 100% 确定问题是什么,但是你尝试过吗?
I'm not 100% sure what the problem/question is, but have you tried...