简体   繁体   English

链接不返回首页

[英]Link not going back to home page

I have researched this to death including on this page. 我对此进行了深入研究,包括在此页面上。 My index page is outside my html folder and when I hit the nav link it will not take me back home(index page). 我的索引页面不在我的html文件夹之外,当我点击导航链接时,它不会带我回家(索引页面)。 I have seen a few post on here regarding this situation, see below: 我在这里看到了有关这种情况的一些帖子,请参见下文:

There are also two special directory names: . 还有两个特殊的目录名称:。 and ..: 和..:

. means "current directory" 表示“当前目录”

.. means "parent directory" ..表示“父目录”

but I have tried several see below for examples that I have tried. 但我已经尝试过以下几个示例。 The index page is on/in the root directory (folder), all the other nav links work as they are in the html folder and they are up one level. 索引页位于根目录(文件夹)上/中,所有其他导航链接都像在html文件夹中一样工作,并且位于上一级。

I have tried: 我努力了:

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

Out of desperation I have tried several things I knew would not work, I would really appreciate your assistance in this matter. 出于绝望,我尝试了几项我无法解决的事情,非常感谢您在此问题上的协助。

littleone 小家伙

In my opinion the safest way is using 我认为最安全的方法是使用

<a href="/">index</a>

This will move the user to the root directory no matter in which directory the user currently is. 无论用户当前在哪个目录中,这都会将用户移动到根目录。

It's quite short which can be helpful too. 它很短,也可能有帮助。 In most cases you can omit index.html because the server uses this file automatically if you visit a directory. 在大多数情况下,您可以省略index.html因为如果您访问目录,服务器将自动使用此文件。

I'm no web server specialist, but I'm sure you're saving your index.html in the incorrect location. 我不是Web服务器专家,但是我确定您将index.html保存在错误的位置。

Your /html folder is your ROOT folder, anything outside of it isn't accessible via a URL. 您的/html文件夹是您的ROOT文件夹,它之外的任何内容都无法通过URL访问。 I'm sure there are ways to override that, but I have never seen anyone do this even in the most complex projects I've worked in. 我敢肯定有很多方法可以覆盖它,但是即使在我从事过的最复杂的项目中,我也从未见过有人这样做。

For example, your site www.yoursite.com is located in the /html of your server. 例如,您的网站www.yoursite.com位于服务器的/html中。 So if you have your index.html file outside of that folder, that file can't be accessed or served at all. 因此,如果您的index.html文件位于该文件夹之外,则根本无法访问或提供该文件。

The common sense solution is to move your index.html file to the /html folder. 常识解决方案是将index.html文件移动到/html文件夹。 When you do this you can then use a slash in your href , like so: 执行此操作后,可以在href使用斜杠,如下所示:

<a href="/">Index</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM