Skip to content


Subversion checkout URL

You can clone with
Download ZIP


[Routing] Cannot specify port for route with hostname #7592

dchesterton opened this Issue · 4 comments

4 participants


By default the router uses the port of the current request when linking to an external site and there's no way to override it.

For example, an application that runs on port 8888, when generating a url from a route such as below, will generate the url "//{id}".

    pattern: /article/view/{id}

Also, if you try to specify a port number in the hostname, e.g.

    pattern: /article/view/{id}

It will generate a url similar to "//{id}".

My first thought would be to introduce a 'port' parameter, which can be used to specify the port, and if it's not provided fall back to the port for the current request?

We only use the hostname parameter to generate url's for an external site which we need to link to, so I'm not sure how this works in regards to matching a route.


:80 is not part of the hostname.


Nope, agreed, but there's currently no way to specify it so I tried that and thought I'd note the behaviour.


That's not supported at the moment and I'm not sure we want to support that anyway. The hostname feature is there to be able to manage sub-domains which are mostly always using the same port. So, I'm closing it for now.

@fabpot fabpot closed this

I sometimes use port-based hosting in testing, especially with mobile devices.

At the moment, I am using a hack in web/app.php and web/app_dev.php (I put it before the bootstrap line, definitely before the kernel boot):

if (!empty($_SERVER['FORCE_HTTP_HOST'])) {

Then in the Apache vhost:


(yes, it means a separate vhost for each site; if your vhost is complex you could use an include).

I don't like putting things in app.php though, it could quickly become unmaintainable. Digging around in the code, I found it difficult to see where Symfony parses the host variables (is it even in the Guzzle code?) Maybe Symfony could provide a way to have a "hostname map" of some kind, or make this logic easier to extend?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.