0

Using has all of the issues on anchor-tags that were described in this question on base tags making it hard to use on my site.

I have a navigation menu in my site which references different parts of my site

for example

main/
  |_index.html
  |_section1/
       |_1a.html
       |_1b.html

and the navigation section on each page looks like

<div id="nav">
  <ul>
    <li><a href="index.html">home</a></li>
    <li><a href="section1/1a.html">1a</a></li>
    <li><a href="section1/1b.html">1b</a></li>
  </ul>
</div>

This works fine for all the pages on in the main folder but for pretty obvious reasons fails when I'm viewing a page in the section1 folder. I can't use <base> because I have a large number of anchors in documents (and I'm using markdown so I cant change the reference format easily).

I'm concerned that if I use absolute references on all my pages, when I upload this site to a server it will be a huge amount of work to replace the absolute reference on each page with a different one.

In addition main is a few levels down in my /home/ directory and I would prefer not to have to type a long path-name each time I refer to something if possible

I guess if I was pushed I could use sed to change all instances of the absolute path with something else but I wondered if there was an easier, obvious way of dealing with this in html that I'm missing. thanks

Community
  • 1
  • 1
Tahnoon Pasha
  • 5,848
  • 14
  • 49
  • 75
  • Although longwinded, you could create a section1 folder in the section1 folder (and a section2 folder, I'm imagining) and use a .htaccess file with RedirectMatch to send them to the right place. – Grim... Aug 26 '13 at 11:33
  • This is normally handled using server-side programming or standalone tools that generate pages. This means a large variety of technologies, and in the choice of technology should depend on many other considerations too. I don’t see what you could use *in HTML*, beyond the `base` tag, which should generally be avoided. – Jukka K. Korpela Aug 26 '13 at 12:21
  • Thanks @JukkaK.Korpela do you know of client side solutions to this question. – Tahnoon Pasha Aug 27 '13 at 06:42
  • It would be relatively straightforward to manipulate URLs on a page using JavaScript. But I don’t see the point in that, especially since it would block search engines from following correct links on your pages. – Jukka K. Korpela Aug 27 '13 at 06:51
  • Thanks @JukkaK.Korpela, the reason is given in my comment to Leo.T.Abraham answer below. This wont be exposed to search engines so it shouldn't matter. If you post an answer describing the javascript you think might work or a link to a site/question that points me in the right direction I'd be happy to mark that up as an answer. – Tahnoon Pasha Aug 27 '13 at 07:02

1 Answers1

1

You can make use of htaccess, if you can't use <base> in HTML

Leo T Abraham
  • 2,407
  • 4
  • 28
  • 54
  • thanks @LeoTAbraham I've tried this but I dont have access to server side scripting. (I'm going to put the site on a network drive and provide a link to the index.html). I tried the .htaccess solution and it didn't work. Do you know of any client side solutions? – Tahnoon Pasha Aug 27 '13 at 06:41
  • 1
    @TahnoonPasha Sorry... I don't know. – Leo T Abraham Aug 27 '13 at 06:47