开发者

400 Bad Request with Symfony2 and html5boilerplate redirect rules

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开发者_Python百科 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 =(


I tried with your config and had no problem to reach my Symfony2 setup.

Try to redirect your requests to app_dev.php instead of app.php so you can track the real error.

Or am I missunderstanding your question?


I'm not 100% sure what the problem/question is, but have you tried...

<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
  RewriteRule ^(.*)$ /$1/ [R=301,L]

  RewriteRule "(^|/)\." - [F]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜