为什么路径以'/'开头指向'C:/'?

发布于 2025-01-11 04:31:16 字数 1072 浏览 1 评论 0 原文

我在 localhost 的路径 C:/xampp/htdocs/seintian.altervista.org 中创建了一个站点,然后将其托管在托管平台 (Altervista)。

在该目录中进行了几个月的编程后,我将 localhost 中站点的根目录更改为 C:/xampp/htdocs ,因为这样我就可以运行通过搜索 http://localhost/ 来创建站点,并且使用路径 /sub/dir/of/the/site 而不是像 这样的相对路径../sub/dir/of/the/site,然而

,它们以某种方式指向路径 C:/ 而不是 C:/xampp/htdocs,即 Apache 站点的 DOCUMENT_ROOT (本地托管由 XAMPP 提供支持)。

另外,我尝试将服务器文件夹上传到Altervista,看看是否有效,但是-您可以自己检查此处< /a> - 也不起作用,响应“在 [...] 处找不到文件或目录”错误。

即使 DOCUMENT_ROOT 常量设置为 C:/,/path/to/file 指向 C:/ 是否正常xampp/htdocs?而且,无论如何,我怎样才能使像 /sub/dir/of/the/site 这样的路径指向 DOCUMENT_ROOT ,预期如何?

PS:只是说,页面 head 部分的 link 元素中的某些路径正确指向正确的路径,例如位于 <代码>C:/xampp/htdocs/assets。这怎么可能? PHP 就讨厌我吗? :'(

提前致谢 <3

I have created a site in localhost in the path C:/xampp/htdocs/seintian.altervista.org and then I hosted it in a hosting platform (Altervista).

After some months of programming in that directory I changed the root directory of the site in localhost to, simply, C:/xampp/htdocs because in that way I thought that I would have been able to run the site by searching http://localhost/ and, also, to use the paths /sub/dir/of/the/site instead of the relative ones like ../sub/dir/of/the/site, etc.

However, they somehow point to the path C:/ instead of C:/xampp/htdocs that is the DOCUMENT_ROOT of the Apache site (the local hosting is powered by XAMPP).

Plus, I tried to upload the server folder to Altervista, to see if there worked, but - and you can check by yourselves here - also there it didn't work, responding with a "file or directory not found at [...]" error.

Is it normal that /path/to/file points to C:/ even if the DOCUMENT_ROOT constant is set to C:/xampp/htdocs? And, in any case, how can I make possible that paths like /sub/dir/of/the/site point to the DOCUMENT_ROOT, how expected?

PS: just to say, some paths in link elements in the head section of the page, point correctly to the right path, for example the assets of the page situated in C:/xampp/htdocs/assets. how is it possible? Does PHP just hate me? :'(

Thanks in advance <3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云之铃。 2025-01-18 04:31:16

/... 指向默认存储,因此在您的情况下它是 C:

而网页 /... 中的链接链接到 http 服务器的根目录(不要将目录路径与 URL 路径混合,它们不一样),

因此这些链接指向相同的位置,但具有不同的含义:

file_get_contents('/etc/dir/xampp/htdocs/assets/images/a.js');
<html>
   <head>
     <script src="/assets/images/a.js"></script>

我个人建议通过将 __DIR__ 附加到 PHP 中使用的所有路径来使您的站点可移植:

// C:/xampp/htdocs/index.php
ROOT_DIR = __DIR__;

...

file_get_contents(ROOT_DIR  . '/assets/images/a.js');

/... points to default storage, so in your case it's C:.

While links in webpage /... links to root directory of http server (do not mix directory path with URL path, they are not the same)

So these are pointing to same location, but has different meaning:

file_get_contents('/etc/dir/xampp/htdocs/assets/images/a.js');
<html>
   <head>
     <script src="/assets/images/a.js"></script>

I personally suggest to make your site portable by appending __DIR__ to all paths that are used in PHP:

// C:/xampp/htdocs/index.php
ROOT_DIR = __DIR__;

...

file_get_contents(ROOT_DIR  . '/assets/images/a.js');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文