Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
dchesterton opened this Issue · 4 comments

4 participants

@dchesterton

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 "//example.com:8888/article/view/{id}".

my_route:
    pattern: /article/view/{id}
    hostname: example.com

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

my_route
    pattern: /article/view/{id}
    hostname: example.com:80

It will generate a url similar to "//example.com:80:8888/article/view/{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.

@stof
Collaborator

:80 is not part of the hostname.

@dchesterton

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

@fabpot
Owner

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
@fazy

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'])) {
    $_SERVER['HTTP_HOST'] = $_SERVER['FORCE_HTTP_HOST'];
}

Then in the Apache vhost:

SetEnv FORCE_HTTP_HOST foo.my-domain

(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.