XAMPP 相对网址无法正常工作 [英] XAMPP relative urls not working correctly
问题描述
在,它试图获取 localhost/images/... 而不是 localhost/exampleSite/images/...
我的文件结构是:
C:\xampp\htdocs\exampleSite\
我在多个项目中都遇到过这个问题,之前曾使用过绝对 URL,但现在我只是想在页面上进行一些快速更新,而我无法在我的本地主机上正确查看它.
如果您不想弄乱整个网站的 src 属性,您可以考虑更改配置指令.
您可以通过编辑 C:\xampp\apache\conf\httpd.conf
中的 DocumentRoot
设置来重新定位它.
当前应该设置为:
C:/xampp/htdocs
改为:
C:/xampp/htdocs/exampleSite
和您的相对链接 <img src="/images/sidenav/analysis-2.gif"/>
应该可以正常工作.
注意:
- 不要忘记在进行更改后重新启动 XAMPP 服务器.
- 进行这些更改后,您的前导
/
将始终指向exampleSite
文件夹.如果您决定稍后更改根目录,请为您选择的根文件夹重复该过程.
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.
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 in C:\xampp\apache\conf\httpd.conf
.
It should be currently set as :
C:/xampp/htdocs
Change it to:
C:/xampp/htdocs/exampleSite
and your relative link as <img src="/images/sidenav/analysis-2.gif" />
should be working fine.
NOTE:
- Don't forget to restart your XAMPP Server after making changes.
- After these changes, your leading
/
will always direct to theexampleSite
folder. Should you decide to change the root later, repeat the process for the root folder of your choice.
这篇关于XAMPP 相对网址无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!