3

I have this html saved as test (without extension)

<!DOCTYPE html>
<html lang="en">
    <head>
        <base href="/">
    </head>
    <body>
        <a href="link">link</a>
    </body>
</html>

File is saved in subdirectory aa of local root server directory so in browser it is available with http://localhost/aa/test . Base href is set to '/' as this is required by framework I use.

I'd like to define link as relative to current url (http://localhost/aa/test/link) but browser combine as relative to current directory (http://localhost/aa/link). How can I achieve this without using any scripting ? I'd like to avoid putting part of current path into href attribute.

edit

  1. added base href
  2. added doctype
koral
  • 2,807
  • 3
  • 37
  • 65
  • 1
    Either use a `base` element, or modify the `href` attribute accordingly. – CBroe Aug 31 '16 at 10:23
  • Have you tried this `link` ? – d.coder Aug 31 '16 at 10:29
  • @CBroe added base href to html as I need it. – koral Aug 31 '16 at 10:33
  • @d.coder I'd like to avoid putting part of current path into href attribute. – koral Aug 31 '16 at 10:33
  • Well then there isn’t much you can do – you need to either supply the correct relative URL in the `href` attribute, or use some kind of script. – CBroe Aug 31 '16 at 10:36
  • Check this other question on [Stackoverflow](http://stackoverflow.com/questions/296873/basic-html-how-to-set-relative-path-to-current-folder) if it answers your question: – dvsakgec Aug 31 '16 at 10:48
  • @dvsakgec how did you obtain the ability to comment with 1 reputation point? I'm just curious. – Marcos Pérez Gude Aug 31 '16 at 11:10
  • 1
    Kind of contradictory, isn't it? On one hand, you need to refer all the URLs to the root, due to your framework (Which is it?). And on another hand, you need the URLs to be relative to the current. I'd suggest to tune the framework properly, better... – Little Santi Aug 31 '16 at 11:14
  • Can't be done. Detailed explanation is in [this SO](http://stackoverflow.com/questions/5457885/relative-urls-and-trailing-slashes) answer. – koral Aug 31 '16 at 11:28
  • Does this answer your question? [Relative URLs and trailing slashes](https://stackoverflow.com/questions/5457885/relative-urls-and-trailing-slashes) – Lety Nov 12 '20 at 15:44

0 Answers0