3

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 =(

domudall
  • 418
  • 3
  • 14

2 Answers2

2

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?

xPheRe
  • 2,333
  • 24
  • 33
  • 1
    Tried the config without any of the extra html5boilerplate config, you're right, it does work. Think the problem is separate to the redirects. Thanks =) will keep searching for the cause, not to do with the above though. – domudall May 31 '11 at 12:57
1

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>
Jack Read
  • 21
  • 1
  • Already tried unfortunately, the issue is with the request when the final block is put on. 400 Bad Request is returned.. Think its to do with the HTTP steps as a whole. – domudall May 31 '11 at 03:10