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

Closed
dchesterton opened this Issue Apr 7, 2013 · 4 comments

Comments

Projects
None yet
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

This comment has been minimized.

Show comment Hide comment
@stof

stof Apr 7, 2013

Member

:80 is not part of the hostname.

Member

stof commented Apr 7, 2013

:80 is not part of the hostname.

@dchesterton

This comment has been minimized.

Show comment Hide comment
@dchesterton

dchesterton Apr 7, 2013

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

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

@fabpot

This comment has been minimized.

Show comment Hide comment
@fabpot

fabpot Apr 12, 2013

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.

Owner

fabpot commented Apr 12, 2013

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 Apr 12, 2013

@fazy

This comment has been minimized.

Show comment Hide comment
@fazy

fazy Nov 11, 2014

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?

fazy commented Nov 11, 2014

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?

@korotovsky korotovsky referenced this issue in korotovsky/SingleSignOnIdentityProviderBundle Jun 8, 2016

Closed

No route found for "GET /sso/login/" #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment