Valid from Symfony v2.1 to v4. 1+
If you want to use the base URL for a Symfony application, you must use getSchemeAndHttpHost() combined with getBaseUrl() , similar to how getUri() works, except for the path to the router and the query string.
{{ app.request.schemeAndHttpHost ~ app.request.baseUrl }}
For example, if the URL of your Symfony website is located at https://www.stackoverflow.com/app1/ , then these two methods return the following values:
getSchemeAndHttpHost
https:
getBaseUrl
/app1
Note: getBaseUrl() includes the name of the script file (i.e. /app.php ) if it is /app.php in your URL.
Matt Janssen Dec 23 '15 at 17:40 2015-12-23 17:40
source share