简体   繁体   English

href =“ /”有什么用? 在锚标签中?

[英]What is the use of href=“/”? in anchor tag?

I've seen it in many website and I was wondering what it does. 我在许多网站上都看到过它,我想知道它的作用。 If someone could clear my doubt it would be great. 如果有人能消除我的怀疑,那将是很好。 Thanks in advance. 提前致谢。

There are three types of http urls (hyperlinks): http url(超链接)有三种类型:

  1. Absolute, includes full domain : http://example.com/folder/foo.htm 绝对,包括完整域: http://example.com/folder/foo.htm : http://example.com/folder/foo.htm
  2. Relative to current document: folder/foo.bar 相对于当前文档: folder/foo.bar
  3. Relative to current domain: /folder/foo.bar - note / at the beginning. 相对于当前域: /folder/foo.bar注意/开头。

This url / belongs to third group - it defines default document at the domain root. 这个url /属于第三组-它定义了域根目录下的默认文档。

So click on <a href="/">Go home</a> will navigate to the domain frontpage. 因此,点击<a href="/">Go home</a>将导航至域首页。

This / means the root directory from that app or website... A couple of examples... /表示该应用程序或网站的根目录...一些示例...

Let's suppose you have a django app in /home/me/pythonprojects/demo1 with this approach, the / in your django apps would point to demo1 location. 让我们假设你有一个Django应用程序/home/me/pythonprojects/demo1这种方法,在/在你的Django的应用程序将指向demo1的位置。

Or in apache when you have /var/www/html/project1 , the / from project1 will be that absolute adress, this way you can have project1, project2,..., projectX in the /var/www/html directory and all of these apps will have their own / and you will not care where your app is in. 或者在apache中,当您拥有/var/www/html/project1/var/www/html/project1中的/将是绝对地址,这样您就可以在/var/www/html目录中拥有project1,project2,...,projectX和所有这些应用程序中的每个将具有自己的/并且您将不在乎您的应用程序在哪里。

Hope it is a bit clearer 希望它更清晰

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

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