URL:同名的文件和目录?

发布于 2024-11-29 14:12:59 字数 1199 浏览 1 评论 0原文

在 URL 方案中,如果目录和文件具有相同的名称是否有任何不利之处?

我提供了一个例子来说明我的意思:

假设您想要进行分页。您可以这样做:

http://example.com/watches/page1
http://example.com/watches/page2
http://example.com/watches/page3
http://example.com/watches/page4

您可以将其解释为:有一个目录“watches”,其中包含 4 个文件 - “page1”到“page4”。

现在,第一页可能是访问频率很高,因此缩短其链接是有意义的:

http://example.com/watches
http://example.com/watches/page2
http://example.com/watches/page3
http://example.com/watches/page4

第一个链接仍将显示第 1 页,但“page1”被保留。并且它不会重定向到,

http://example.com/watches/page1

因为这会强制再次往返服务器。

您可以将其解释为:有一个名为“watches”的文件(显示手表类别中的第一页),并且有一个目录 'watches' 有 3 个文件 - 'page2' 到 'page4'。

这又是我的问题: 如果一个目录和一个文件,是否有任何不利之处有相同的名字,比如上例中的“手表”?

以下是我对此的想法:

就 SEO 而言,这可能不是不利的,因为据我所知搜索引擎没有目录的概念,因此将 URL 视为字符块。只要 URL 不同(在我的示例中就是这样),搜索引擎就不会打扰。

如果有人想使用像 wget 这样的网络爬虫来归档我的网站并将其内容镜像到本地硬盘上,这可能会是一个问题,因为大多数文件系统不允许多个文件/目录有相同的名字。然而,恕我直言,这个问题可以很容易地解决,例如通过使用 wget 的 -E 选项,它将 .html 扩展名添加到 HTML 文件,而不是目录。

除此之外,我认为没有任何问题。你?

In an URL scheme, is it in any way disadvantageous if a directory and a file have the same name?

I provide an example to illustrate what I mean:

Let's say you want to do pagination. You could do it like this:

http://example.com/watches/page1
http://example.com/watches/page2
http://example.com/watches/page3
http://example.com/watches/page4

You could interpret that as: There is a directory 'watches' which has 4 files – 'page1' to 'page4'.

Now, the first page is probably going to be accessed quite often, so it makes sense to shorten the link to it:

http://example.com/watches
http://example.com/watches/page2
http://example.com/watches/page3
http://example.com/watches/page4

The first link will still show page 1, but the 'page1' is left off. And it will NOT redirect to

http://example.com/watches/page1

as that would force another round trip to the server.

You could interpret that as: There is a file named 'watches' (which shows the first page in the category watches), and there is a directory 'watches' which has 3 files – 'page2' to 'page4'.

Here is my question again: Is it in any way disadvantageous if a directory and a file have the same name, like 'watches' in the above example?

Here are my thoughts on it:

In terms of SEO, it probably is not disadvantageous, as AFAIK search engines have no notion of directories and thus treat URLs as blobs of characters. And as long as the URLs are different – which they are in my example – the search engine does not bother.

In case someone wants to archive my website with a web crawler like wget and mirror its contents on a local HDD, it could be a problem, as most file systems don't allow more than one file/directory to have the same name. However, IMHO this could easily be solved, e.g. by using wget's -E option, which adds the .html extension to HTML files, but not to directories.

Other than that, I see no problems. Do you?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千秋岁 2024-12-06 14:12:59

总的来说,现在的 Web 服务器不会将 URI 读取为目录和文件,而是将其读取为资源的地址,并且在许多(如果不是大多数)情况下,URI 和资源之间的路由很复杂。以这个问题为例,它不是目录中的 HTML 文件。此外,网络爬虫也不必处理不能用作文件名的结构。

我不太清楚你的问题是什么,但我希望这会有所帮助。

By and large nowadays web servers do not read URI's as a directories and files, but as an address for a resource, and in many if not the majority of cases, the routing between the URI and the resource is complex. This question as an example is not an HTML file in a directory. Also web crawlers don't as a consequence have to cope with structures that don't work as filenames either.

I'm not sure quite what your issue is, but I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文