middlewares / www

PSR-15 middleware to add or remove the www subdomain
MIT License
4 stars 1 forks source link

Remove port 80 from url when using SlimPHP 4 behind Traefik #1

Closed frugan-dev closed 3 years ago

frugan-dev commented 3 years ago

Hi,

I am using Traefik v2.4.8 in front of my SlimPHP 4 application. Traefik manages HTTPS connections and communicates with Apache in the backend on port 8080.

When I enable your Www Middleware, it redirects by adding port 80 to the url. If I analyze the call at this point https://github.com/middlewares/www/blob/master/src/Www.php#L40 I find that:

$uri->getScheme() -> 'https'
$uri->getPort() -> 80

If I change this line https://github.com/middlewares/www/blob/master/src/Www.php#L52 from so:

->withHeader('Location', (string) $uri->withHost($host));

to so:

->withHeader('Location', (string) $uri->withPort(null)->withHost($host));

the problem is apparently solved..

I don't understand if there is a wrong setting in my stack (Traefik + Apache + PHP-FPM), or if it depends on this method https://github.com/slimphp/Slim-Psr7/blob/master/src/Uri.php#L303 which in my case returns 'false'.

Thanks to anyone who can give me a tip..

oscarotero commented 3 years ago

I think this is a problem out of this middleware, because it receives an Uri with https scheme and the port 80 (it should be port 443 or scheme http).

frugan-dev commented 3 years ago

Thanks you, as I imagined.. I try to figure out if it depends on my stack, thanks you!