防止域名尾随斜线 [英] Preventing trailing slash on domain name

查看:29
本文介绍了防止域名尾随斜线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的网站显示为 www.mysite.com,而不是 www.mysite.com/

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

Apache 是否默认在域名后添加斜杠,还是浏览器附加它?如果我想使用 .htaccess 阻止这种情况,那么 url 重写规则是什么?

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?

推荐答案

如果您提出要求:

http://myhost.com

请求在 HTTP 中需要如下所示:

获取/HTTP/1.0
主机: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 HTTP/1.0
主机:myhost.com

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

这将是非法请求.

注意:

http://myhost.com/page

是合法的,因为它转换为:

is legal, because it translates to:

GET/page HTTP/1.0
主机:myhost.com

GET /page HTTP/1.0
Host: myhost.com

这篇关于防止域名尾随斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆