惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
博客园_首页
H
Help Net Security
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
GbyAI
GbyAI
Scott Helme
Scott Helme
D
Docker
Hacker News: Ask HN
Hacker News: Ask HN
P
Privacy & Cybersecurity Law Blog
Jina AI
Jina AI
雷峰网
雷峰网
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
G
GRAHAM CLULEY
C
Cisco Blogs
The Hacker News
The Hacker News
F
Full Disclosure
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
Recent Announcements
Recent Announcements
G
Google Developers Blog
量子位
K
Kaspersky official blog
Cisco Talos Blog
Cisco Talos Blog
The Cloudflare Blog
A
About on SuperTechFans
C
Cybersecurity and Infrastructure Security Agency CISA
Last Week in AI
Last Week in AI
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security Blog
Martin Fowler
Martin Fowler
T
Tenable Blog
P
Palo Alto Networks Blog
H
Heimdal Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
Schneier on Security
Schneier on Security
The Register - Security
The Register - Security
F
Fortinet All Blogs
Stack Overflow Blog
Stack Overflow Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
The Blog of Author Tim Ferriss
N
News and Events Feed by Topic
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
V
V2EX
爱范儿
爱范儿

博客园 - 柯君

基于OceanBase的行列混合存储架构适配HTAP的方案改造 知识图谱内容综述(一) 访问控制技术的一些研究分析 Python学习摘要201802 机器学习-梯度下降参数调优小结 用尽洪荒之力学习Flask源码 Flask类的属性和方法大全 Flask第三方工具组件介绍 Flask自带的常用组件介绍 Centos下部署Flask Python Tips阅读摘要 技术博文阅读摘要分享-9月 Python2和Python3的差异 通过Django Channels设计聊天机器人WEB框架 Windows下配置vue的环境 Redis的安装及学习 MongoDB学习笔记 Windows下安装MongoDB Chatbot思考录
url末尾的斜杠作用探秘
柯君 · 2018-06-29 · via 博客园 - 柯君

今天突然好奇,想区分www.abc.com/efg 和www.abc.com/efg/这两个网址的区别。即分析一下url末尾加个斜杠是否有特殊的效果。

找到网上的介绍:

当Web服务器接收到对某个末尾不含斜杠的url请求时,例如“www.abc.com/efg”,这时服务器会搜索网站根目录下有没有名为“abc”的文件,如果没有就把abc当做目录处理,然后返回abc目录下的默认首页。当Web服务器接收到的是末尾带斜杠的请求时就会直接当做目录处理。

同样,根据微软官方文档Internet Explorer and Connection Limits

Another web-performance tip: When generating hyperlinks, always include a trailing slash if possible. For instance, navigating to http://msdn.microsoft.com/ie takes one more roundtrip than http://msdn.microsoft.com/ie/. When the browser navigates to the /ie url, the server merely sends down a 301 to the /ie/ url. Both links work, but the second version is faster.

ok,根据上述的材料,我们是否可以认为url加上斜杠能加快访问速度。
接下来通过一个简单的flask项目测试一下:
Flask框架通过路由绑定url和视图函数,绑定http://127.0.0.1:5000/abchttp://127.0.0.1:5000/def/url。

总结:

  1. 网站要进行统一的标准,要么用户访问和网站url路由都在url末尾不加斜杠,要么都不在url末尾加斜杠,如果采用统一的标准在访问速度不会有任何的区别。
  2. 但是用户的行为是不可以限制和预测的。用户可能会在url后面加个斜杠。
  3. 两个技术方案各有利弊:1.网站路由url不加斜杠,用户自己加斜杠之后访问404,但是不会出现重定向的问题;2.网站路由url加斜杠,用户访问的url无论加不加斜杠均可访问正常,但是不加斜杠的访问链接会做重定向,影响访问速度。

<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">