Search code examples
phpapache.htaccessdocument-root

Modify the value of $_SERVER['DOCUMENT_ROOT'] via .htaccess


Can I use .htaccess to change the return value of $_SERVER['DOCUMENT_ROOT'] for local development only?

Currently, $_SERVER['DOCUMENT_ROOT'] returns,

C:\wamp\www

but I want it to return this,

C:\wamp\www\website_folder

Is it possible?


Solution

  • Well, $_SERVER['DOCUMENT_ROOT'] returns the document route as defined in your server's config. I think you use http://localhost/website_folder (or host.com/website_folder) to access the site.

    It doesn't return the website folder. You can create a new virtual host and set its document route to the appropriate folder, failin that, you cannot. Frankly, $_SERVER['DOCUMENT_ROOT']. IF you want the website path, you can always use

    $serverPath=$_SERVER['DOCUMENT_ROOT']."/website_folder"