2

How can i make a directory inside htdocs act as the root directory?

Example:

Going to "localhost/<directory>"

Serves "C:/Apache/htdocs/<directory>" as the "$_SERVER['DOCUMENT_ROOT']"

I tried this, it did not change the "$_SERVER['DOCUMENT_ROOT']"

<VirtualHost localhost/<directory>:80>
     DocumentRoot C:\Apache\htdocs\<directory>
     ServerName localhost/<directory>
     ServerAlias localhost/<directory>
<Directory "C:\Apache\htdocs\<directory>">
    AllowOverride All
    Require local
</Directory>
</VirtualHost>
0

Don't mixup apache virtual directories (like http://servername/directory) and the physical path (like c:\folder)

<VirtualHost localhost:80> <-- this is where the apache
                                process listens (just
                                servernames/ips/ports)
     DocumentRoot C:\Apache\htdocs\<directory>
     <-- This path is served in the virtual directory "/"
         (and what you are searching for)

     ServerName localhost
     <-- This is the server's name on which this directive is active

     ServerAlias localhost
     <-- Theese are alternate server's names. NAMEs, no path at all.
</VirtualHost>

The directive doesn't to do anything here, regarding the virtual path; it contains stuff on how apache should act in this directory, not where it is.

  • 1
    But i am still having to remove the <directory> part after localhost via .htaccess, the localhost/<directory> still does not act as the root like localhost/ does. – amt May 8 at 12:47
  • The <directory> directive can either be in your conf (as above), or placed as a .htaccess file in the path itself. Both would be correct - so you can leave your <Directory> in your <VirtualHost> element. – bjoster May 8 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.