XAMPP 相对 url 无法正常工作
在 http://www.exampleSite.com/aPage.php 上,以下图像加载正确,
<img src="/images/sidenav/analysis-2.gif" />
但在 http://localhost/exampleSite/aPage.php 处,它尝试获取 localhost/images/..代替。 localhost/exampleSite/images/...
我的文件结构是:
C:\xampp\htdocs\exampleSite\
我在多个项目中都遇到过这个问题,并且之前曾求助于绝对 URL,但现在我只是想快速制作一些页面上更新,但我无法在本地主机上正确查看它。
on http://www.exampleSite.com/aPage.php, the following image loads correctly
<img src="/images/sidenav/analysis-2.gif" />
but at http://localhost/exampleSite/aPage.php, it tries to get localhost/images/... instead of localhost/exampleSite/images/...
My file structure is:
C:\xampp\htdocs\exampleSite\
I have had this problem across multiple projects, and have previously resorted to absolute URLs, but now I am just trying to make some quick updates on a page, and I cannot view it correctly on my localhost.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不想弄乱整个网站的 src 属性,您可以考虑更改配置指令。
您可以通过编辑
C:\xampp\apache\conf\httpd.conf
中的DocumentRoot
设置来重新定位它。当前应设置为:
将其更改为:
并且您的相对链接
应该可以正常工作。
注意:
/
将始终定向到exampleSite
文件夹。如果您决定稍后更改根目录,请对您选择的根文件夹重复此过程。If you don't want to mess up with the src attributes throughout your website, you may consider changing configuration directives.
You can relocate it by editing the
DocumentRoot
setting inC:\xampp\apache\conf\httpd.conf
.It should be currently set as :
Change it to:
and your relative link as
<img src="/images/sidenav/analysis-2.gif" />
should be working fine.NOTE:
/
will always direct to theexampleSite
folder. Should you decide to change the root later, repeat the process for the root folder of your choice.删除第一个
/
,使其变为Remove the first
/
so that it becomes<img src="images/sidenav/analysis-2.gif" />