从同一子目录(Apache)加载html-file中的脚本

Load scripts in html-file from same subdirectory (Apache)

本文关键字:html-file 加载 脚本 Apache 子目录      更新时间:2023-09-26

我想问一个最愚蠢的问题,但我搜索了一会儿,还是没有弄清楚。

我在Apache DocumentRoot下有以下文件结构:

DocRoot
 - page1
   - ...
 - webapp
   - index.html
   - somescript.js

与index.html有一个脚本标签看起来像

<script src="somescript.js" type="text/javascript">

我如何配置Apache服务https://myhostname.com/webapp,使脚本得到正确加载?Page1应该在https://myhostname/page1下保持可访问。

当前的行为是找不到somescript.js,因为请求是https://myhostname.com/somescript.js.

我做NOT想为此设置一个虚拟主机或编辑html文件(get的生成)。

webapppage1位于var/www/html?如果是这样,可能你的JS文件在html文件夹中搜索。

你至少有两个解:

  1. <script src="/webapp/somescript.js" type="text/javascript">
  2. 为webapp和page1配置虚拟主机。所以,你可以通过webapp.myhostname.compage1.myhostname.com子domens连接到这些页面,<script src="somescript.js" type="text/javascript">将为它们工作,在它们的文件夹
  3. 中搜索