简体   繁体   中英

Relative paths from subdomain - HTML

This seems like a simple question but it's baffling me. Let's say my domain is: bar.com and my subdomain is foo.bar.com.

If I'm on foo.bar.com/1/2 and I go back a directory through a link with a relative path (href="../") it will take me to foo.bar.com, not foo.bar.com/1 as I'd expect it to. Why is this? How do I get to foo.bar.com/1 with a relative path?

Side question: If foo.bar.com is masking another directory (let's say bar.com/foo, and I go to href="/", will that take me to the root of the entire domain (bar.com) or just to the root of the subdomain (foo.bar.com)?

If the current page is http://foo.bar.com/1/2 , browser thinks 2 is a document under the directory 1 . So if you have ../ , it goes to its parent directory, which is the root directory. If you want to link to http://foo.bar.com/1/ , you can use href=./ .

I don't quite understand your side question. Generally if the URL displayed in browser is bar.com/foo , then href="/" takes users to bar.com/ ; if the URL displayed in browser is foo.bar.com/ , then href="/" takes users to foo.bar.com/

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