Valid from Symfony v2.1 through v4.1+
If you want the base URL to a Symfony application, you should use getSchemeAndHttpHost()
concatenated together with getBaseUrl()
, similar to how getUri()
works, except without the router path and query string.
{{ app.request.schemeAndHttpHost ~ app.request.baseUrl }}
For example, if your Symfony website URL lives at https://www.stackoverflow.com/app1/
, then these two methods return these values:
getSchemeAndHttpHost
https://www.stackoverflow.com
getBaseUrl
/app1
Note: getBaseUrl()
includes the script filename (ie /app.php
) if it's in your URL.