20

This is a stupidly easy question, however after searching for a long time I have yet to yield any results.

My question is as follows.

I have a webpage with the url http://domain.com/mypage/ladeda/

I have a link on this page.

<a href="/1/">Page 1</a>

That link sends me to http://domain.com/1/

<a href="1/">Page 1</a>

That link takes me to http://domain.com/mypage/1/

How do i get my link to take me to http://domain.com/mypage/ladeda/1/

without having to extract all the aspects of the page url and put them within the href.

Many Thanks

Thomas Clowes
  • 4,529
  • 8
  • 41
  • 73

2 Answers2

25
<base href="/mypage/ladeda/" />
...
<a href="1/">(goes to http://domain.com/mypage/ladeda/1/)</a>

Via the <base> element.


But!
<a href="1/">Page 1</a> should take you to http://domain.com/mypage/ladeda/1/ already provided that (a) you don't use a <base> element already and (b) the current resource is really http://domain.com/mypage/ladeda/ (with a trailing slash).

jensgram
  • 31,109
  • 6
  • 81
  • 98
1
<a href="/mypage/ladeda/1">Page 1</a>

If the current page isn't in the same directory (real or virtual) as the target page, you're going to have to specify a complete path. Either relative, or absolute. There's no way around it.

James Gentes
  • 7,528
  • 7
  • 44
  • 64
Marc B
  • 356,200
  • 43
  • 426
  • 500
  • I did specify "without having to extract all the aspects of the page url and put them within the href." Thanks – Thomas Clowes Sep 01 '11 at 14:42
  • 2
    If the current page isn't in the same directory (real or virtual) as the target page, you're going to have to specify a complete path. Either relative, or absolute. There's no way around it. – Marc B Sep 01 '11 at 14:54
  • @MarcB there is no way around it – Ashish Kamble Jan 11 '21 at 06:52