I am developing several Web sites on my computer, and I use relative links like the good designer I am. 😃 Let's say I have a folder in "/Program Files/Apache/Apache Group/htdocs" called "website1" that contains a Web site. I have another Web site in a folder called "website2". To clarify, the two folders would be "/Program Files/Apache/Apache Group/htdocs/website1" and "/Program Files/Apache/Apache Group/htdocs/website2", respectively. When I test locally, I call files like this: "http://localhost/website1" and "http://localhost/website2". Let's say I publish my website1 remotely on the internet at "http://www.website1.com". Because of the way I had to link in my php code locally, what is "http://localhost/website1/index.php" on my machine must be "http://www.website1.com/website1/index.php" on my remote site in order for links, images, css, etc. to work. I would prefer for "http://localhost/website1/index.php" to map to "http://www.website1.com/index.php". Keep in mind that I do not control the remote servers; the hosting company does.

Is there some way to set my local document root so it can change variably to my different Web sites? Is there some way to set it up to where "http://website1.localhost" or "http://website1@localhost" (or something) can be used as the root for the website1 site and "http://website2.localhost" or "http://website2@localhost" can be used as the site root for the website2 site, etc.? Hope this makes sense, and I hope you guys can help me!

    You should read up on Virtual hosts in apache.

    in your httpd.conf file you can enable name based virtual hosting and give a directive like so...

    <VirtualHost *>
    ServerAdmin youremail@address.com
    DocumentRoot /path/to/root/directory/for/website1
    ServerName www.website1.com
    ServerAlias website1.com
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    CustomLog /path/to/log/directory/for/website1/combined_log combined
    ErrorLog /path/to/log/directory/for/website1/error_log

    <Directory "/path/to/root/directory/for/website1">
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>

    <Directory "/path/to/root/directory/for/website1/secret/stuff/">
    AllowOverride AuthConfig
    </Directory>
    <Directory "/path/to/more/website1/secret/stuff/">
    AllowOverride AuthConfig
    </Directory>

    </VirtualHost>

    Some variation of that will do....

    tha_mink

      Don't forget to make suitable DNS ot /etc/hosts entry 🙂

        Don't forget to make suitable DNS ot /etc/hosts entry

        Wha??? You don't need anything in /etc/hosts. You DO need domain aliasing with whoever is managing your domain name so that the world knows that users.site.com points to your machine.

          I may be mistaken here, but even though you don't need anything in /etc/hosts, some people slip commonly used names in there to avoid the overhead of name resolution. Obviously means you are responsible for keeping it up to date...

            My site is being hosted remotely, and that remote hosting has nothing to do with my machine other than the fact that I ftp files to the remote machine from it.

            At no time will anyone from outside my network be accessing the files on my machine through the server. The server is strictly for local testing.

            Once I do set that Virtual Host up for each individual site, how do I access it from my browser for testing? I'm not sure if you guys are understanding my question...

            For example, is it "website1@localhost"? "website1.localhost"? Does that example up there even set it up so it does that?

              Write a Reply...