基本 HTML - 子文件夹的相对路径(使用目录名称)可以在桌面上使用吗?

发布于 2024-10-22 23:56:19 字数 492 浏览 1 评论 0原文

我正在 Mac OS 10.6.6 上做一些基本的 HTML 练习。

假设我在这里:

rootfolder/index.html

,我想去这里:

rootfolder/subfolder/index.html

我知道我可以使用相对路径来创建链接:

<a href="subfolder/index.html">link to subfolder</a>

^ 这在我的浏览器中适用于我。

如果我想缩短 href,我可以这样做:

<a href="subfolder/">link to subfolder</a>

当我在浏览器中单击短版本时,该链接会将我带到桌面上的文件夹(而不是浏览器中的页面)

我想知道,做这些文件需要位于网络主机环境中 在浏览器中工作的简短版本?

I am doing some basic HTML exercises on a Mac OS 10.6.6.

Say I am here:

rootfolder/index.html

and I want to go here:

rootfolder/subfolder/index.html

I understand I can use the relative path to make a link:

<a href="subfolder/index.html">link to subfolder</a>

^ this works for me in my browser.

And if I wanted to shorten the href, I could just do this:

<a href="subfolder/">link to subfolder</a>

When I click the short version in my browser, the link takes me to the folder on my desktop (not to the page in my browser)

I'm wondering, do the files need to be in a web host environment for
the short version to work in a browser?

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

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

发布评论

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

评论(4

往日 2024-10-29 23:56:19

/bob/ => 时/bob/index.html 有效,通常是因为服务器已将其列为目录索引,例如使用 Apache...

DirectoryIndex index.html index.php

...意味着在文件夹的请求中,它会首先查找查看 index.htmlindex.php 是否存在(按顺序)。

因此,如果您从本地文件系统的文件夹(即在 file: 协议上)运行它,它没有服务器并且不知道应该请求一个空白目录index.html

When /bob/ => /bob/index.html works, it is generally because the server has listed it as its directory index, e.g. with Apache...

DirectoryIndex index.html index.php

...meaning in the request of a folder, it will first look up to see if an index.html or index.php exists (in that order).

So if you are running it from the folders of your local filesytem (i.e. on the file: protocol), it has no server and does not know that a blank directory should request index.html.

抱猫软卧 2024-10-29 23:56:19

当请求指向目录的 url 时,index.html(或 index.cgi 或 default.asp 或其他)的服务是由服务器而不是浏览器完成的。它通常是作为配置设置的结果来完成的。

它既不是 HTML 的属性,也不是 url 的属性。

如果您的浏览器不提供 index.html 服务(而且我不知道有哪个浏览器提供服务),那么您就已经回答了自己的问题。

The serving of index.html (or index.cgi or default.asp or whatever) when requesting a url that points to a directory is done by the server, not the browser. It is usually done as a result of configuration setting.

It's neither a property of HTML nor a property of urls.

If your browser doesn't serve index.html — and I don't know any that do — then you've answered your own question.

蓝海似她心 2024-10-29 23:56:19

Mac OS 预装了 Apache(最常用的开源 Web 服务器)。您可以通过以下方式进行设置:转到“系统偏好设置”,选择“共享”偏好设置窗格,然后选中该框以打开“个人网络共享”。

打开个人网络共享后,http://addressofyourcomputer/~yourusername/ 将指向站点目录在 Mac OS 中您的用户文件夹中(即 /Users/yourusername/Sites/)。在 Apache 运行时,如果您转到 http://addressofyourcomputer/~yourusername/subfolder/,它将在事实上,如果该子文件夹中有一个index.html 文件,则提供/Users/yourusername/Sites/subfolder/index.html。

但是,如果不打开个人网络共享,就不会运行服务器,因此您的浏览器实际上只是直接访问计算机的文件系统。因此,当您请求一个文件夹时,它实际上会返回该文件夹,而 Apache 服务器知道 /subfolder/ 实际上是对 /subfolder/index.html 的请求,并将相应地重定向您。

Mac OS comes with Apache (the most commonly-used open-source web server) pre-installed. You can set it up by going to System Preferences, choosing the "Sharing" preference pane, and then checking the box to turn on Personal Web Sharing.

Once you've turned on Personal Web Sharing, http://addressofyourcomputer/~yourusername/ will point to the Sites directory in your user's folder in Mac OS (i.e., /Users/yourusername/Sites/). With Apache running, if you go to http://addressofyourcomputer/~yourusername/subfolder/, it will in fact serve up /Users/yourusername/Sites/subfolder/index.html if there is an index.html file in that subfolder.

Without turning on Personal Web Sharing, though, there is no server running, and so your browser is really just directly accessing your computer's filesystem. As a result, when you ask for a folder, it literally returns you that folder, whereas Apache server knows the convention that /subfolder/ is really a request for /subfolder/index.html and will re-direct you accordingly.

叶落知秋 2024-10-29 23:56:19

默认页面设置/重定向仅适用于 Web 服务器。浏览器不具备进行此类重定向的智能(?)。所以第二个选项行不通。

The default page setting/redirection works only on web servers. The browser do not have intelligence(?) for such redirection. So the second option will not work.

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