Disable Port removing on rewrite

Francis Daly francis at daoine.org
Fri Sep 16 18:50:55 UTC 2016

On Fri, Sep 16, 2016 at 06:05:34PM +0000, Schütrumpf, Niklas wrote:
> 16. September 2016 19:34, "Francis Daly" <francis at daoine.org> schrieb:

Hi there,

> > rewrite ^(.*[^/])$ http://$http_host$1/ permanent;
> > 
> > This would break any clients that do not send the Host: header that you
> > expect -- possibly that matters; possibly it doesn't.

> Thanks alot!
> I used your rewrite tipp!
> I modified the rule and added a if statement:
>     if (-d $request_filename) {
> 	    rewrite [^/]$ $scheme://$http_host$uri/ permanent;
>     }

Yes, that looks like it should work; and it will do mostly the same as
the internal trailing-slash redirect, which is good.

> I think nowdays almost every browser sends the HTTP header (i hope so)

They will pretty much all send a Host: header or they won't work very
well on the public internet; I'm not sure if they all include the :port
within the Host: header.

But it does not matter what "all" do; only what the ones that you care
about do. Hopefully that is something that you can test adequately :-)

Good that you have a solution.


Francis Daly        francis at daoine.org

More information about the nginx mailing list