symfony on virtual host document root problem

2019-09-02 09:01发布

问题:

Im trying to deploy symfony on virtual host.

mod_rewrite converts /web URLs to domain root URLs (domain.com/image.gif is turning internaly into domain.com/web/image.gif).

But thanks to web is executed internaly from /web dir, Symfony is still thinking it has document root there and prefixes any url_for() URLs with /web.

So when i have route:

show_books:
  url: /books

..and iam asking for:

url_for('@route_name')

Symfony is generating:

/web/books

I cant change hosting behaviour, i need to have web request pointed into symfony root path and internaly redirected into /web dir and i want to symfony ignore the point it is executed from |hostname-document-root|/web

回答1:

I found the insert of this code into top of my front controller (/web/index.php) as good solution:

$_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'] = '/index.php';