$ _SERVER ['DOCUMENT_ROOT']

First of all, if you read this in advance for your patience, I am pretty new to PHP and have a problem that I will try to explain / describe.

//set default path ///var/www/vhosts/www.mydomain.com/httpdocs/ $url = 'http://mydomain.com/skins/coolblue/tmp'; $url2 = 'http://mydomain.com/skins/coolblue/tmp'; $doc = $_SERVER['DOCUMENT_ROOT']; $path = '/templates/'; $actual_url = $doc.'/skins/coolblue/tmp'.$path; 

(I had a developer who originally created my site and set up my server, but he left now) my site is hosted on a dedicated server with the plesk control panel, so when I called Godaddy and asked for their meaning for ['DOCUMENT_ROOT'] , they gave me * / var / www / vhosts / www.mydomain.com / httpdocs / *

My problem is that I am using dynamic URLs like subdomain.mydomain.com (which is already configured and working correctly), which in turn determines the content, and also that the output comes from a specific script with $_SERVER['DOCUMENT_ROOT'] as above, url is always a static url in www format. ++++. I want the url to be dynamic.

Is there a way around this, or can I change $ doc = $_SERVER['DOCUMENT_ROOT']; to the actual script url and add a dynamic domain variable i.e. http://$subdomain/domain.com ? I tried almost all the options without luck. Do you have any suggestions? Aside, is $doc = $_SERVER['DOCUMENT_ROOT']; necessary, or was it a developer choice instead of writing a path? - Thanks again.

0
source share
2 answers

If you use the .htaccess file to forward subdomains to subfolders (this is pure hypothesis), and, in fact, you must have a path to the file system, you can set the environment variable for redirection, for example:

 RewriteCond %{HTTP_HOST} subdomain\.site\.tld$ [NC] RewriteRule ^(.*)$ /subfolder/$1 [L,E=APPEND_ROOT:subfolder/] 

Then a simple modification should give you the right way:

 $doc = $_SERVER['DOCUMENT_ROOT'] . $_ENV['REDIRECT_APPEND_ROOT']; 

$_SERVER['DOCUMENT_ROOT']; necessary if you do not want to configure the full path name for each site (which is a type of pain).

If you are not using .htaccess to resolve your subdomains, and you configured them in the Apache configuration, it should point to the correct physical home for each subdomain.

+1
source

$_SERVER['DOCUMENT_ROOT'] - path., Try using 'SERVER_NAME' or 'REQUEST_URI'

'SERVER_NAME'

The hostname of the server under which the current script is running. If the script is running on a virtual host, this will be the value defined for that virtual host.

or

'REQUEST_URI'

The URI that was provided to access this page; e.g. '/index.html'.

+1
source

All Articles