I would like to know if this kind of setup is possible as I'm having a lot of trouble setting it up. I am trying to set up a website with a file structure like this:
- project1 (folder)
- index.php
- style.css
- include.php
- admin (folder)
- index.php
- admin (folder)
The parent "project1" folder is located on 'server1' in D:\Projects\project1.
The website is accessed via virtual directory "http://server1/project1".
I would like to be able to write all paths for includes, images srcs, stylesheets etc, in the format '/style.css' so that the files can be found regardless of where they are required. E.g. the following link should work whether it's placed in the 'project1' folder or the 'admin' folder:
<link rel="stylesheet" type="text/css" href="/style.css">
EDIT: as mellamokb suggested, using href="/project1/style.css" seems to work from both 'index.php' files. However I can't seem to find a similar solution for the PHP INCLUDE.
If I use this...
<?php include_once '/include.php'; ?>
...in both index.php files, the one in the admin directory cannot find the file.
I expected $_SERVER['DOCUMENT_ROOT'] to return "D:\Projects\project1" but it returns D:\staging and I can't work out why. I've tried a few different methods of setting the project 'root' but I've just ended up confusing myself even more! The virtual root of the project should be 'http://server1/project1' and the physical root should be D:\Projects\project1, but I can't work out how to force this.