skip to Main Content

First of all, if you read this, thank you in advance for your patience,- I’m fairly new at PHP and have an issue which 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 originally build my site and configure my server, but he’s gone now)
my site is hosted on a dedicated server with plesk control panel, so when I called Godaddy and asked them the value for ['DOCUMENT_ROOT'], they gave me * /var/www/vhosts/www.mydomain.com/httpdocs/*

my issue is, I use dynamic urls eg subdomain.mydomain.com(which is already configured and works properly), which in turn determines content, and being that the output comes from a particular script using the $_SERVER['DOCUMENT_ROOT'] as above, the url is always the static url in the www.++++ format. I want the url to be dynamic.

Is there a way to go around this, or can I change the $doc = $_SERVER['DOCUMENT_ROOT']; to the actual url of the script and add in the dynamic domain variable ie http://$subdomain/domain.com? I have tried just about every variation of the path with no luck. Do you have any suggestions? As an aside, is $doc = $_SERVER['DOCUMENT_ROOT']; a necessary, or was it the choice of the developer instead of writing the path out? – Thank you again

2

Answers


  1. If you’re using a .htaccess file to forward your subdomains to subfolders (this is pure conjecture), and having the filesystem path is, in fact necessary, you could set an environment variable on redirect to take advantage, eg:

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

    Then a simple modification should give you the correct path:

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

    $_SERVER['DOCUMENT_ROOT']; is necessary if you don’t want to have to configure the full path name for each site (which is kind of a pain).

    If you aren’t using .htaccess to resolve your subdomains, and you have them set up in the Apache configuration, it should point to the correct physical home for each subdomain already.

    Login or Signup to reply.
  2. $_SERVER['DOCUMENT_ROOT'] is path., try using 'SERVER_NAME' or 'REQUEST_URI'

    ‘SERVER_NAME’

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

    or

    ‘REQUEST_URI’

    The URI which was given in order to access this page; for instance, ‘/index.html’.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search