I have re-written this entire post as I realized it originally did not make much sense (That would be a funny comment for a program).
I'm developing a web project in localhost with a very organized and deeply nested directory structure.
My current project directory:
# Absolute path /Users/Username/Sites/myproject/ # Localhost path localhost/~Username/myproject/
With PHP files, I can specify includes using the absolute path:
The following anchor tag using an absolute path to the file:
Clicking the link causes a 404 error:
The requested URL /Users/Username/Sites/myproject/blog/ was not found on this server.
With the following example, looking at the URL on the 404 page, I can see that the server attempted to look for the file under the localhost root directory, rather than my machine's root directory:
Easy enough, I'll just point the file using an absolute path in the localhost directory:
Ah! A solution! I actually discovered this solution while making this edit to the post and, though it will work in all my directories no matter how nested, it's going to cause some serious problems down the line. First of all, this method does not work for PHP includes, PHP starts its file searching from the root of the machine, not the web server. This requires absolute paths that start all the way at the
/User level, which will need to be changed when I upload this to me 3rd party host. I can think of another, much worse case, where I upload all the files to a 3rd party host, and have to go through and change all the links, to something like:
myproject will be the root folder (
www.myproject.com). Sure, changing a few href, src, and php include locations won't be too bad, but I'm going to have to change every path on every file, which will be extremely time consuming and, based on how large this project is, close to impossible. And then when the nightmare comes of having to edit a file or two, change some CSS, etc, I'll download the related files via FTP and then I will have to change all the paths again to work on my local machine. This would be a nightmare.
So, my question is, how can I configure the OSX Apache web server to recognize
myproject as the root folder in the sites directory? Is is as simple as editing
httpd.conf? I'm hesitant to edit that file because if I mess anything up I'm screwed. Even if it is as simple as changing the
DocumentRoot, what if I'm working on multiple projects at once? I'm not going to want to go in every time and change
DocumentRoot just to get my paths to work. I think it would be pretty cool for each top-level directory in the
Sites folder to be its own root folder for any files or directories inside of it, if that makes any sense. Anyway, any advice would help, I'm kind of dead in the water right now.