HTML链接尾部斜线 [英] HTML link trailing slash

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

问题描述

w3schools 文档说:


如果没有子文件夹地址的尾部斜杠,您可能会向服务器生成两个请求。许多服务器会自动为该地址添加一个斜线,然后创建一个新的请求。

Without a trailing slash on subfolder addresses, you might generate two requests to the server. Many servers will automatically add a trailing slash to the address, and then create a new request.

目前还不清楚这意味着什么。在href网址中添加尾部斜线有什么不同?是否有关于添加尾部斜线的最佳做法。

It is not clear what exactly this means. What difference does it make to add a trailing slash in the href urls, is there a best practice regarding adding a trailing slash.

推荐答案

这些是两个不同的网址:

These are two different URLs:

http://example.com/foo
http://example.com/foo/

通常(但并非总是)请求第一个URL会触发服务器回复一个 301永久重定向到第二个URL。然后,浏览器必须向第二个URL发出第二个请求。

Often, but not always, requesting the first URL will trigger the server to reply with a 301 Permanent Redirect to the second URL. The browser will then have to make a second request to the second URL.

当URL映射到服务器文件系统上的一个目录时,这是最常见的情况和 index.html (或其他目录索引)正在被加载。

This is most commonly the case when the URL is mapped on to a directory on the server's file system and the index.html (or other directory index) is being loaded.

内容处于动态状态的服务器生成(例如像Perl的Catalyst这样的MVC框架)不太可能这样做。在这种情况下,您经常需要更仔细地链接到哪里,因为相对URL的解析方式与这两个URL不同。

Servers where the content is being dynamically generated (e.g. with an MVC framework like Perl's Catalyst) are less likely to do this. In that case you often have to be even more careful with where you link to because relative URLs will resolve differently from the two URLs.

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

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