我在 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
发布评论
评论(1)
/...
指向默认存储,因此在您的情况下它是C:
。而网页
/...
中的链接链接到 http 服务器的根目录(不要将目录路径与 URL 路径混合,它们不一样),因此这些链接指向相同的位置,但具有不同的含义:
我个人建议通过将
__DIR__
附加到 PHP 中使用的所有路径来使您的站点可移植:/...
points to default storage, so in your case it'sC:
.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:
I personally suggest to make your site portable by appending
__DIR__
to all paths that are used in PHP: