Apache 根目录相对链接
使用 apache 2,我有一个简单的虚拟主机容器:
<VirtualHost 127.0.0.1>
ServerName developmentServer
DocumentRoot /var/www
</VirtualHost>
该站点可以访问,但我在站点内使用根相对链接时遇到问题。我有一个位于根级别的“图像”文件夹。当我位于文件夹或子文件夹中时,我想指定相对于根目录的图像路径。 (实际上,无论页面深度如何,所有路径都将是根相对路径。)这目前不起作用:
<img src="/images/file.jpg">
但这将:
<img src="../images/file.jpg">
我理解其中的区别,但我不知道在 Apache 中需要更改什么才能允许我启动所有链接一个“/”,所以它们是相对于根的。我认为有一个配置设置,我不应该依赖 mod_rewrite。有什么建议吗?
Using apache 2, I have a simple virtual host container:
<VirtualHost 127.0.0.1>
ServerName developmentServer
DocumentRoot /var/www
</VirtualHost>
The site is accessible, but I'm having trouble using root relative links within the site. I have an 'images' folder that is located at the root level. When I am within a folder or subfolder, I want to specify an image path that is root relative. (And actually all paths will be root relative regardless of the page depth.) This currently is not working:
<img src="/images/file.jpg">
But this will:
<img src="../images/file.jpg">
I understand the difference, but I do not know what needs to be changed in Apache to allow me start all links with a "/" so they are root-relative. I'm thinking there is a configuration setting, and I shouldn't have to rely on mod_rewrite. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该图像是否位于
/var/www/images/file.jpg
以及您是否通过 HTTP 访问包含该图像的页面 (http://developmentServer/...
)?那么它必须起作用。Is the image located at
/var/www/images/file.jpg
and are you accessing the page containing this image over HTTP (http://developmentServer/...
)? Then it must work.