链接不返回目录?

发布于 2024-10-15 06:24:26 字数 766 浏览 2 评论 0原文

我有一个网站,我们将其命名为 example.com。在这个网站中,我有一些常见问题解答,但构建该网站的人将常见问题解答页面保存在网站上名为“FAQs”的目录下。

例如,常见问题解答页面位于:

example.com/pages/en/faqs/faq-page1.html

请注意 pages/en/ 目录。理想情况下,我希望所有页面都保存在 example.com/index.html 等下,但我无法更改这一点。

无论如何,当我在任何这些常见问题解答页面上时,我尝试链接回主页 index.html ,导航不会转到该页面。例如,当我访问:

example.com/pages/en/faqs/faq-page1.html

时,我尝试链接回主页

example.com/pages/ en/index.html (这是保存索引页的位置)导航将无法工作。相反,它会尝试访问 example.com/pages/en/faqs/index.html

现在我假设发生这种情况是因为我位于“faq”目录中,但是链接时如何返回根目录?该链接的代码很简单:Home。我当然可以输入完整的链接 example.com/pages/en/index.html,这可以解决这个问题,但是还有其他方法吗?

I have a website, let's call it example.com. Within this site, I have some FAQs but the person that built the site saved the FAQ pages under a directory on the site named "FAQs".

As an example an FAQ page would be located at:

example.com/pages/en/faqs/faq-page1.html.

Note the pages/en/ directory. Ideally I would like all the pages to be saved under example.com/index.html etc but I can't change this.

Anyway, when I am on any of these FAQ pages, and I try to link back to say the home page index.html the navigation won't go to the page. So for example, when I am on:

example.com/pages/en/faqs/faq-page1.html

and I try to link back to the home page

example.com/pages/en/index.html (which is where the index page is saved) the nav won't work. Instead it will try to go to example.com/pages/en/faqs/index.html.

Now I am assuming this happens because I am in the "faq" directory, but how do I go back to the root directory when linking? The code for the link is simply <a href="index.html">Home</a>. I could of course just put in the full link example.com/pages/en/index.html, which would solve this but is there another way around this?

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

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

发布评论

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

评论(3

通知家属抬走 2024-10-22 06:24:26

您需要提供 Home 的相对文件路径

或者,您可以使用以下命令指定站点根目录的链接
Home

... 有特殊含义文件路径中,.. 表示上一个目录,. 表示当前目录。

所以 HomeHome 相同;

You need to give a relative file path of <a href="../index.html">Home</a>

Alternately you can specify a link from the root of your site with
<a href="/pages/en/index.html">Home</a>

.. and . have special meanings in file paths, .. means up one directory and . means current directory.

so <a href="index.html">Home</a> is the same as <a href="./index.html">Home</a>

陪你搞怪i 2024-10-22 06:24:26

有两种类型的路径:绝对路径和相对路径。对于硬盘中的文件和 URL 中的目录来说,这基本上是相同的。

绝对路径以斜杠开头。无论您在何处使用它们,它们始终指向相同的位置:

  • /pages/en/faqs/faq-page1.html

其余路径为相对路径(所有不以斜线开头的路径)。它们指向的位置取决于您使用它们的位置

  • index.html 是:
    • /pages/en/faqs/index.html 如果从 /pages/en/faqs/faq-page1.html 调用
    • /pages/index.html 如果从 /pages/example.html 调用
    • 等等

调用。还有两个特殊的目录名称:...

  • . 表示“当前目录”
  • .. 表示“父目录”

您可以使用它们构建相对路径:

  • ../index.html如果从 /pages/en/faqs/faq-page1.html 调用,则为 /pages/en/index.html
  • ../../index.html如果从 /pages/en/faqs/faq-page1.html 调用,/pages/index.html

一旦您熟悉了这些术语,它就是很容易理解它出了什么问题以及如何解决它。您有两个选择:

  • 使用绝对路径
  • 修复相对路径

There are two type of paths: absolute and relative. This is basically the same for files in your hard disc and directories in a URL.

Absolute paths start with a leading slash. They always point to the same location, no matter where you use them:

  • /pages/en/faqs/faq-page1.html

Relative paths are the rest (all that do not start with slash). The location they point to depends on where you are using them

  • index.html is:
    • /pages/en/faqs/index.html if called from /pages/en/faqs/faq-page1.html
    • /pages/index.html if called from /pages/example.html
    • etc.

There are also two special directory names: . and ..:

  • . means "current directory"
  • .. means "parent directory"

You can use them to build relative paths:

  • ../index.html is /pages/en/index.html if called from /pages/en/faqs/faq-page1.html
  • ../../index.html is /pages/index.html if called from /pages/en/faqs/faq-page1.html

Once you're familiar with the terms, it's easy to understand what it's failing and how to fix it. You have two options:

  • Use absolute paths
  • Fix your relative paths
原谅我要高飞 2024-10-22 06:24:26

要转到链接中的目录,请使用 ..。这意味着“向上一个目录”,因此您的链接将如下所示:

<a href="../index.html">Home</a>

To go up a directory in a link, use ... This means "go up one directory", so your link will look something like this:

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