本文介绍了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/...

but at http://localhost/exampleSite/aPage.php, it tries to get localhost/images/... instead of localhost/exampleSite/images/...

我的文件结构是:

C:xampphtdocsexampleSite

C:xampphtdocsexampleSite

我在多个项目中都遇到过这个问题,并且以前使用过绝对 URL,但现在我只是想在页面上进行一些快速更新,我无法在我的本地主机上正确查看它.

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.

推荐答案

如果你不想弄乱整个网站的 src 属性,你可以考虑更改配置指令.

If you don't want to mess up with the src attributes throughout your website, you may consider changing configuration directives.

您可以通过编辑 C:xamppapacheconfhttpd.conf 中的 DocumentRoot 设置来重新定位它.

You can relocate it by editing the DocumentRoot setting in C:xamppapacheconfhttpd.conf.

目前应该设置为:

C:/xampp/htdocs

改成:

C:/xampp/htdocs/exampleSite

您的相对链接 <img src="/images/sidenav/analysis-2.gif"/> 应该可以正常工作.

and your relative link as <img src="/images/sidenav/analysis-2.gif" /> should be working fine.

注意:

  • 进行更改后不要忘记重新启动您的 XAMPP 服务器.
  • 进行这些更改后,您的前导 / 将始终指向 exampleSite 文件夹.如果您决定稍后更改根目录,请为您选择的根文件夹重复该过程.
  • Don't forget to restart your XAMPP Server after making changes.
  • After these changes, your leading / will always direct to the exampleSite folder. Should you decide to change the root later, repeat the process for the root folder of your choice.

这篇关于XAMPP 相对 URL 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 03:08