I have this structure in my localhost (I use Apache2 and Ubuntu):
/var/www/
-- PROJECT1
---- index.php
---- layout.php
---- etc.
-- PROJECT2
---- index.php
---- layout.php
---- somefile.php
---- ADMIN
-------- index.php
-------- etc.
---- CSS
-------- main.css
(The ones with CAPITALS are folders)
So, when I'm in the root of the project, I can use links correctly if I want to refer into some file, for example, if I'm inside index.php
from the PROJECT2, I can do this:
<a href="somefile.php">Click here to go to some file</a>
And this will actually refer the user to the somefile.php
file. But if I'm inside the admin folder, this doesn't work, so I tried to put a slash before the file, so it would be like this:
<a href="/somefile.php">Click here to go to some file</a>
But no, this actually refers to the path /var/localhost/somefile.php
.
So, I wonder if there's a way to change the root path with a code or something like this, because I'd like to have the path for project1 like /var/www/PROJECT1
and for project2 like /var/www/PROJECT2
.
I've also found this , but it actually changes the root directory for all the projects I have.
So, what can I do?
Thanks!
Hi, I found the solution!
What I did, is adding a line of code in my header, and now it works perfectly. This is what I've used:
<base href="/project1/">
Look into virtual hosts. That way for different projects you can have different hosts defined which is a better way to separate them. Also all your project then will live in a root of their virtual hosts
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.