Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing trailing slash on domain name

I want my site to show up as www.mysite.com, not www.mysite.com/

Does Apache add a trailing slash after a domain name by default, or does the browser append it? If I want to prevent this using an .htaccess, what would the url rewrite rule be?

like image 706
Yarin Avatar asked Sep 08 '11 22:09

Yarin


1 Answers

If you request:

http://myhost.com

The request needs to look like this in HTTP:

GET / HTTP/1.0
Host: myhost.com

For historical reasons, some browsers did append the slash because otherwise it translates to

GET <nothing> HTTP/1.0
Host: myhost.com

Which would be an illegal request.

Note that:

http://myhost.com/page

is legal, because it translates to:

GET /page HTTP/1.0
Host: myhost.com

like image 75
pmau Avatar answered Oct 13 '22 11:10

pmau