繁体   English   中英

参考.css 和脚本生成的图像 HTML

[英]referring to .css and images from script-generated HTML

我在主目录中有一个带有 static HTML 页面的站点。 这些 HTML 页面使用相对路径来引用图像、css 和链接,即

<img src="images/myimg.gif">

<a href="contactUs.html">Contact Us</a>

I also have a monolithic script whose URL is, ie http://mysite.com/myScript which uses "extra path info" to select functions... ie http://mysite.com/myScript/products shows a list of products . 因此,在从脚本生成的 HTML 中,我需要参考图像、css 和如下链接:

<img src="../images/myimg.gif">

<a href="../contactUs.html">Contact Us</a>

The problem is now I want to start moving common HTML into include files, (eg common header and footer), but the fact that the script and the static HTML refer to relative resources in different ways is complicating matters.

我不想使用绝对路径,因为当我的同事尝试在 DramWeaver 中处理页面时,这会扰乱她的工作,而且这也会降低站点的灵活性。

解决此问题的最佳方法是什么? One idea I had was to use URL rewriting in Apache to allow the URL to http://mysite.com/products to really use http://mysite.com/myScript/products but I don't have experience with URL rewriting so我不知道这有多容易。 Another idea I had was to use the META BASE attribute in HTML but I don't like the fact that I would have to hard-code that into every HTML page, and it would have to have the full URL hard-coded (eg http://mysite.com/ )进入每一个。 有什么建议吗?

您不能在开头使用斜杠引用您的图像,以便所有链接到的文件都来自根目录,无论您在目录结构中有多深? 例如:

<img src="/images/myimg.gif" />

编辑:

您可以使用$_SERVER获取路径,然后使用substr_count计算路径中的斜杠数。 根据该数字添加尽可能多的../ 这对你有用吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM