我有一个索引文件存储在我的服务器上的 public_html 文件夹下,因此可以公开访问它。
那个地址是http://example.com/randomlocation/anotherlocation/index.html
在看起来像 public_html/randomlocation/anotherlocation/index.html 的服务器上
但是,问题是我的用于显示页面并运行它的 css、js 和 img 文件位于公共(public) html 部分之外的另一个级别,我无法指定到达那里的相对路径或基本路径,这将是这样的:
home/site/folder/randomfolder/anotherfolder/location/styles.css
例如:
<link rel="stylesheet" href="http://example.com/randomfolder/another folder/assets/css/emojione.min.css"/>
<link rel="stylesheet" href="/home/examplesite/folder/folder/folder/folder/assets/css/styles.css" />
好像不行。我已经尝试了“/”相对路径的所有变体,但无法弄清楚我缺少什么才能提取这些文件。
最佳答案
通常当服务器有一个 public_html 文件夹时,服务器被配置为只有该文件夹内的文件才能通过网络公开访问。 (通过这种方式,您可以在 public_html
之外拥有诸如服务器配置和私有(private)文件之类的东西,人们将无法通过将 url 放入浏览器来访问它们。)
换句话说,您应该将 css/js/images 移动到 public_html
中。您可以将它们放在子目录中以保持井井有条,但它们都应位于 public_html
下的某个地方。
关于css - 从基本文件夹中提取 CSS 和 JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40111039/