change the web root directory in apache (xampp)

萝らか妹 提交于 2019-12-14 02:14:12

问题


When I echo "PHP_SELF" in localhost running on xampp, I get the project folder as the echoed text e.g.

// index.php

<?php echo $_SERVER["PHP_SELF"]; ?>

The answer is

/a3-ver-9.0/index.php

but if I was on a server with a domain, that line would just return "/index.php"

Is there any way I can temporarily changes the default root in xampp to reflect this?

The reason is because I use absolute paths from root to include resources e.g. images. however these absolute paths will not work if the root is not set correctly!

Cheers

EDIT

To make things more clear...

I have a website with php files that return parts of the page e.g. header.php and footer.php etc.

I have an installation of wordpress and in the wordpress template, I include these files. and because im including these files from different directories, the paths inside the included files must be absolute.

however the files in the header.php are included like:

<img src="/images/image1.jpg" />

now this include is correct, and when I've finished the project and upload it to my server it will correctly retrieve the image.

but when working with localhost, the root folder "/" is the folder where ALL my local projects are kept.

So i need a way to temporarily change the localhost root for each project, so i dont have to mess about changing a load of paths when the project is ready for upload!

Hope this made more sense

However when working on local host


回答1:


Best way to solve this is using virtual hosts for your projects locally. So something like www.project.local actually shows your project.

Here is a tutorial how to achieve this in xampp.




回答2:


Okay, now I see what you mean, here you go this will help you, just change the root to the folder of your current project, for example:

"C:/xampp/xampp/htdocs/a3-ver-9.0/"


来源:https://stackoverflow.com/questions/8785509/change-the-web-root-directory-in-apache-xampp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!