Suppose that the user is currently located http://www.example.com/folder1/folder2/
. I would like to be able redirect them to the home page at http://www.example.com/
. The catch is, I don't know I'm two folders deep and I don't know what the domain name i开发者_开发百科s. To do this, what should the href
be in a link? For example, href='../../'
would seem to work if I know a priori I'm two folders deep, but in general I won't know that. I want a link that will always direct me right to the home page, regardless of how 'deep' I am and regardless of the domain name of the site. How do I do this?
Thanks in advance!
"/" will direct to the root of your website:
<a href="/">Home</a> <!-- http://site.com/ -->
<a href="/lol/abc.html">ABC</a> <!-- http://site.com/lol/abc.html -->
etc.
Try using a root-relative link, which starts at the root of the site and builds outward. In this case, you want to go directly all the way to the root, so your path would just be /
:
<a href="/">Home</a>
you can use href="/"
to go to the root of a site.
精彩评论