Skip to main content

Posts

Showing posts with the label Virtualhost

PHP : Set document root to be a subdirectory without .htaccess or Virtualhost

Recently I faced a problem with hosting a website on a server to which I have limited access. I was provided with permission only to a sub-directory on the server. I'm habituated to use relative paths, but my root points to the root of server and not my sub-directory. This forced me to use absolute paths at every point. I searched for the solution and end up with two results: .htaccess ot Virtualhost I never tried to understand .htaccess and I don't have access to set Virtualhost . This forced me to try bit harder and here is the outcome. I've created a file named rootpath.php on root directory of my website. ( Note : this is not root '/' of the web server, but my sub-directory) Its contents are as follows: <?php     $relative_path = "/subdirectory";     $server_url = $_SERVER["SERVER_NAME"];     $root = "http://" . $server_url. $relative_path; ?> Now, I include this file on top of every file. Eg: <?php requi...