-1

I have this rewrite rule to direct request to my symfony 2 application:

RewriteCond %{REQUEST_URI}           ^/foo/.*$
RewriteRule ^/foo(/.*)$              /srv/webapps/symfony2/web/app.php [QSA,L]

If I access http://test-server.com/foo/myController I get a symfony exception telling me that it doesn't know how to route foo/myController.

I don't want to add foo to the route in symfony since the application has to work with other URL prefixes as well. How can I make sure that the foo part is not visible by symfony?

BetaRide
  • 445

2 Answers2

1

As it appears that you are attempting to redirect requests made to a specific context path (foo) to a single file, perhaps you would find the following (modified from this apache documentation) useful: Alias /foo /srv/webapps/symfony2/web

  RewriteBase /foo</p>

  RewriteCond /srv/webapps/symfony2/web/%{REQUEST_FILENAME} !-f
  RewriteCond /srv/webapps/symfony2/web/%{REQUEST_FILENAME} !-d
  RewriteRule ^ app.php [PT]
</Directory>

Edit: Alternatively, you could amend your original solution to include the PT flag to pass the rewritten URI through to the application for processing, eg:

RewriteCond %{REQUEST_URI}           ^/foo/.*$
RewriteRule ^/foo(/.*)$              /srv/webapps/symfony2/web/app.php [QSA,PT]

(note that L is implied by PT as noted in the documentation

BE77Y
  • 2,697
1

After all I got it working. My solution looks like this:

Alias /foo /srv/webapps/symfony2/web
<Directory /srv/webapps/symfony2/web >
      AllowOverride None
      Order allow,deny
      Allow from all
      Options +FollowSymLinks

      RewriteEngine On
      RewriteOptions Inherit
      RewriteBase /foo

      # prevent looping from internal redirects
      RewriteCond %{ENV:REDIRECT_STATUS} 200
      RewriteRule ^ - [L]

      ## redirect everything to app.php unless the file realy exists in /web
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^ app.php [last]
</Directory>

I don't know why this happens, but it seams to be important that alias and directory point directly to the symfony web folder. If they point to /srv/webapps/symfony2 and the final rewrite points to web/app.php you get the alias root prepended to the URI.

BetaRide
  • 445