Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link to a page on the current domain without writing the full URL

Let's say the current URL is example.com/test/example

and let's say I want to link to example.com/test/example/another

<a href="/another"> links me to example.com/another

How can I link to example.com/test/example/another without having to put the full URL in the a tag?

like image 622
UserIsCorrupt Avatar asked Jan 29 '12 17:01

UserIsCorrupt


People also ask

How do I link to another page in HTML?

To make page links in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a> tag indicates where the link starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a link. Add the URL for the link in the <a href=” ”>.

How do you make a link go to the top of a Web page?

Definition and Usage Tip: You can use href="#top" or href="#" to link to the top of the current page!


2 Answers

<a href="another">

should do it.

EDIT: My bad, it actually is:

<a href="./another">
like image 70
itdoesntwork Avatar answered Oct 25 '22 10:10

itdoesntwork


I'd suggest using root-relative paths, if you'd prefer not to use absolute paths:

<a href="/test/example/another">Link text</a>

Otherwise, for relative paths, itdoesntwork's answer covers the use-case.

like image 43
David Thomas Avatar answered Oct 25 '22 11:10

David Thomas