HTML Urls - how to append to the existing url

39,519

Solution 1

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

Solution 2

<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.

Share:
39,519
Thomas Clowes
Author by

Thomas Clowes

I am a 27 year old software engineer living and working in the United Kingdom. I am CTO of Double Negative Solutions. We built EthTools.com, PubReviews.com and Revision.net. In my spare time I run, learn about random topics that take my interest, and write a personal blog over at ThomasClowes.com. I write about software, running, economics, and other loosely related topics.

Updated on July 09, 2022

Comments

  • Thomas Clowes
    Thomas Clowes almost 2 years

    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
    Thomas Clowes over 12 years
    I did specify "without having to extract all the aspects of the page url and put them within the href." Thanks
  • Marc B
    Marc B over 12 years
    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.
  • Impulse The Fox
    Impulse The Fox over 5 years
    The missing trailing slash was my mistake. I wasn't aware of this. This should get more attention.
  • Ashish Kamble
    Ashish Kamble over 3 years
    @MarcB there is no way around it