简体   繁体   中英

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):

  1. Absolute, includes full domain : http://example.com/folder/foo.htm
  2. Relative to current document: folder/foo.bar
  3. Relative to current domain: /folder/foo.bar - note / at the beginning.

This url / belongs to third group - it defines default document at the domain root.

So click on <a href="/">Go home</a> will navigate to the domain frontpage.

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.

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.

Hope it is a bit clearer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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