有效地使用相对URL方案 [英] Using a relative URL scheme effectively

查看:85
本文介绍了有效地使用相对URL方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用具有在这个问题的基本标签使它很难在我的网站上使用。



我在我的网站有一个导航菜单,引用我的不同部分site

例如

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

和每个页面上的导航部分看起来像

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

这适用于 main 文件夹,但是当我在 section1 文件夹中查看页面时,显而易见的原因失败。我不能使用< base> ,因为我在文档中有大量的锚点(并且我使用降价,所以我不能轻松更改引用格式) / p>

我担心的是,如果我在所有页面上使用绝对引用,那么当我将此网站上载到服务器时,将需要大量工作来替换绝对引用在每个页面上使用不同的页面。

此外, main 是在 / home / 目录,我宁愿不必在每次引用某些内容时都键入一个长路径名称。



我猜如果我被推送了,我可以使用 sed 来改变绝对路径的所有实例,但我想知道是否有一个更容易,明显的方式来处理这个在HTML中,我失踪了。谢谢

解决方案

您可以使用 htaccess t在HTML中使用< base>


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

解决方案

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

这篇关于有效地使用相对URL方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆