recursive
recursive

Reputation: 11

Nginx redirect without trailing slash

How can I redirect "http://test.com/" to "http://test.com" with Nginx?

I tried

rewrite ^/(.*)/$ /$1 permanent;

But this work only for http://test.com/anything/ not for root

Thanks a lot

Upvotes: 1

Views: 1224

Answers (1)

Danila Vershinin
Danila Vershinin

Reputation: 9845

There is no such thing as a domain requested "without slash".

When you go to https://example.com, your browser will always fetch some URI (path) from the server, and by default, it is /.

So you are simply asking for an impossible thing :-)

P.S. whether a browser displays the trailing slash when a "domain" is requested, varies. For example, Chrome would hide trailing slash for known TLDs while displaying it for local TLDs, e.g.

https://example.com/ => trailing slash hidden

http://example.local/ => trailing slash is shown

Upvotes: 1

Related Questions