diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
index 2b2b9d0b09d4f..8224e0a56bc05 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
@@ -482,6 +482,15 @@ private function addRouterSection(ArrayNodeDefinition $rootNode)
->defaultTrue()
->end()
->booleanNode('utf8')->defaultFalse()->end()
+ ->arrayNode('context')
+ ->info('router request context')
+ ->addDefaultsIfNotSet()
+ ->children()
+ ->scalarNode('host')->defaultValue('%router.request_context.host%')->end()
+ ->scalarNode('scheme')->defaultValue('%router.request_context.scheme%')->end()
+ ->scalarNode('base_url')->defaultValue('%router.request_context.base_url%')->end()
+ ->end()
+ ->end()
->end()
->end()
->end()
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
index a8cb13a34946e..45fd20a1153f3 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
@@ -854,6 +854,11 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
$container->setParameter('request_listener.http_port', $config['http_port']);
$container->setParameter('request_listener.https_port', $config['https_port']);
+ $requestContext = $container->findDefinition('router.request_context');
+ $requestContext->replaceArgument(0, $config['context']['base_url']);
+ $requestContext->replaceArgument(2, $config['context']['host']);
+ $requestContext->replaceArgument(3, $config['context']['scheme']);
+
if ($this->annotationsConfigEnabled) {
$container->register('routing.loader.annotation', AnnotatedRouteControllerLoader::class)
->setPublic(false)
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml
index 49a39360dae38..96ac2c72b4b23 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml
@@ -79,10 +79,10 @@
- %router.request_context.base_url%
+
GET
- %router.request_context.host%
- %router.request_context.scheme%
+
+
%request_listener.http_port%
%request_listener.https_port%
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
index e67bc9f97d507..3d6840d6e602e 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
@@ -413,6 +413,11 @@ protected static function getBundleDefaultConfig()
'https_port' => 443,
'strict_requirements' => true,
'utf8' => false,
+ 'context' => [
+ 'host' => '%router.request_context.host%',
+ 'scheme' => '%router.request_context.scheme%',
+ 'base_url' => '%router.request_context.base_url%',
+ ],
],
'session' => [
'enabled' => false,