Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts

    VirtualDocumentRoot and DocumentRoot help?

    Hello,

    I am using VirtualDocumentRoot to allow me to have unlimited amount of domains for a .local

    Code:
    NameVirtualHost 127.0.0.1
    <VirtualHost 127.0.0.1>
      ServerAlias www.*.local
      ServerAlias *.*.local
      ServerAlias *.local
      UseCanonicalName Off
      VirtualDocumentRoot "C:/wamp/www/Client Sites/%-2"
    </VirtualHost>
    What I would like to have is a domain like
    "domain.local" and "www.domain.local" direct to "C:/wamp/www/Client Sites/domain"
    but something like "dev.domain.local" to direct to "C:/wamp/www/Client Sites/domain/dev"
    and "images.dev.domain.local" to direct to "C:/wamp/www/Client Sites/domain/dev/images".

    However I would also like to be able to have "www." added to the front of any domain and not be included for example "www.images.dev.domain.local" would just direct to the folder location for "images.dev.domain.local" which would be "C:/wamp/www/Client Sites/dev/images".

    Also I would like to know how I can set the DocumentRoot for a VirtualDocumentRoot, as currently with my VirtualDocumentRoot, I can have a domain name like "images.domain.local" but it directs to "C:/wamp/www/Client Sites/domain" and not "C:/wamp/www/Client Sites/domain/images", and no matter what the domain name is the DocumentRoot is always "C:/wamp/www", how can I make it so that if I go to "images.domain.local" the PHP "$_SERVER['DOCUMENT_ROOT']" would equal "C:/wamp/www/Client Sites/domain/images" as that would be the base folder to any files located on "images.domain.local".

    Any help would be grateful, thank you.
    - DJCMBear
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,293
    Thanks
    4
    Thanked 202 Times in 199 Posts
    Use a combination of entries in your hosts file and virtual hosts in Apache to accomplish what you're looking for. Rather than try to explain it in detail here is a small portion of my hosts file followed by the entries in my httpd-vhosts.conf file for Apache (that file resides in the /conf/extra directory under where Apache is installed).

    First the entries in the hosts file:

    Code:
    127.0.0.1       localhost
    
    127.0.0.1     freeresourceguide.mtnlan.com
    127.0.0.1     bearsjustbears.mtnlan.com
    127.0.0.1     cameron-miller.mtnlan.com
    127.0.0.1     internationalindustriesinc.mtnlan.com
    And now the corresponding entries in httpd-vhosts.conf:

    Code:
    #
    # FreeResourceGuide
    #
    
    <VirtualHost *:80>
        ServerName freeresourceguide.mtnlan.com
        ServerAdmin abc@nowhere.com
        DocumentRoot "E:/home2/bearsjus/public_html/FRG"
        DirectoryIndex index.php index.html
    </VirtualHost>
    
    #
    # BearsJustBears
    #
    
    <VirtualHost *:80>
        ServerName bearsjustbears.mtnlan.com
        ServerAdmin abc@nowhere.com
        DocumentRoot "E:/home2/bearsjus/public_html"
        DirectoryIndex index.php index.html 
    </VirtualHost>
    
    #
    # International Industries
    #
    
    <VirtualHost *:80>
        ServerName internationalindustriesinc.mtnlan.com
        ServerAdmin abc@nowhere.com
        DocumentRoot "E:/home2/bearsjus/public_html/III"
        DirectoryIndex index.php index.html index.htm
    </VirtualHost>
    
    #
    # Cameron Miller
    #
    
    <VirtualHost *:80>
        ServerName cameron-miller.mtnlan.com
        ServerAdmin abc@nowhere.com
        DocumentRoot "E:/home2/bearsjus/public_html/CM"
        DirectoryIndex index.php index.html index.htm
    </VirtualHost>
    As you can see, this arrangement allows me to use domain names that are almost identical to what they are in production (just moving the mtnlan portion of the domain). Each name points to a completely different directory and they all function independently.

    As for the aliasing you have, I might suggest using .htaccess to force either the use of or non-use of the www in the domain names. For my purposes I never use the www in development and whether or not it's enforced in production depends on the site (I try not to force it since it really isn't necessary).
    Dave .... HostMonster for all of your hosting needs

  • #3
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Looks good, however I am trying to make it so I don't have to edit the conf file at all to add a new site to the .local domain, I have managed to do a part of it by adding in this code into the conf virtual host, "php_admin_value auto_prepend_file C:/wamp/tools/fixDR.php" to fix the $_SERVER["DOCUMENT_ROOT"] issue so that has been fixed.

    I still however need to find a way to sort the VirtualDocumentRoot issue with the directory issue, for example.

    This Domain:
    Code:
    dev.examples.codes.local
    Should direct to:
    Code:
    C:/wamp/www/Clients Sites/codes/examples/dev
    However it directs to:
    Code:
    C:/wamp/www/Clients Sites/codes
    As you can see the additional sub-domains are not being added in to the path, If nothing can be done I might have to use my old trick to use index.php to detect what to do by the domain being used.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,293
    Thanks
    4
    Thanked 202 Times in 199 Posts
    Sorry what I provided didn't help. I don't edit the configuration file often enough to consider doing it any differently and when I do it only takes a moment to add or change something.
    Dave .... HostMonster for all of your hosting needs

  • #5
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Thanks ok, thank you for offering your help, and I would also do it that way for a quicker solution but with my job I need to have fast site creation within a split second, for example someone wants a new site domain, I have to edit just one file and it is ready to go instead of editing many files to create a new domain name.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #6
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Just bumping this as I still need help.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •