Jump to content

Incorrect RootURL


n00dles101
 Share

Recommended Posts

Hi,

Having another issues trying to move a site up on to my live Host. Seems "RootURL" is not being set correctly.

Site is working fine on localhost.

I'm using the the following code, taken from index.php to check what settings are being retrieved.

$rootPath = dirname(__FILE__);
if(DIRECTORY_SEPARATOR != '/') $rootPath = str_replace(DIRECTORY_SEPARATOR, '/', $rootPath); 
$rootURL = isset($_SERVER['HTTP_HOST']) ? substr($rootPath, strlen(rtrim($_SERVER['DOCUMENT_ROOT'], '/'))) . '/' : '/';

I've just added some debug code to it and uploaded it to my test server.

The new code is

<?php 
  $rootPath = dirname(__FILE__);
  echo "RootPath:".$rootPath."</br>";
  if(DIRECTORY_SEPARATOR != '/') $rootPath = str_replace(DIRECTORY_SEPARATOR, '/', $rootPath); 
  echo "NewRootPath:".$rootPath."</br>";
  echo "HTTP_HOST:".$_SERVER['HTTP_HOST']."<br/>";
  echo "DOCUMENT_ROOT:".$_SERVER['DOCUMENT_ROOT']."<br/>";
  $rootURL = isset($_SERVER['HTTP_HOST']) ? substr($rootPath, strlen(rtrim($_SERVER['DOCUMENT_ROOT'], '/'))) . '/' : '/';
  echo "RootURL:".$rootURL;
  ?>

on my localhost the output is :

RootPath:C:\xampp\htdocs\www.tsp.com
NewRootPath:C:/xampp/htdocs/www.tsp.com
HTTP_HOST:localhost
DOCUMENT_ROOT:C:/xampp/htdocs
RootURL:/www.tsp.com/

While on my live server I'm getting the follwoing:

RootPath:/content/Hosting/d/i/digimute.com/subdomains/lab/web
NewRootPath:/content/Hosting/d/i/digimute.com/subdomains/lab/web
HTTP_HOST:lab.digimute.com
DOCUMENT_ROOT:/content/Hosting/l/a/lab.digimute.com/web
RootURL:ins/lab/web/

Check out the RootURL ??

Where is it getting this from ??

Anyone any clues?

Thanks for the help.

Mike.

Link to comment
Share on other sites

Hi Mike,

if you check the code, it seems there are two different paths referenced: one is /sub/ directory in your domain dir on server, the second one is DOCUMENT_ROOT itself.

Now, this is somewhat unusual situation; Where the incorrect rootUrl comes from - it's easy:

_/content/Hosting/d/i/digimute.com/subdoma|ins/lab/web
-/content/Hosting/l/a/lab.digimute.com/web|

note: I added the pipe character "|" to let you see where the 'substr' happens.

On most servers, the DOCUMENT_ROOT would identify itself as '/c/H/d/i/digimute.com/s/lab/web/' (long words ommited), so the rootUrl would be pure '/'. But somehow, your host gives two totally different directories. I think your best bet for now is to hack the core (= put $rootUrl = '/'; after this code).

And maybe post your var_dump($_SERVER), so we can compare it to default Apache $_SERVER contents and come back with some more bullet-proof code.

Adam

Link to comment
Share on other sites

I came to the same conclusion as Adam looking at this. I've not seen the DOCUMENT_ROOT show as something different from checking the dirname(__FILE__) before. But clearly it's possible for that to happen, since we're seeing it here. So it's something that ProcessWire should probably be on the look out for. But I think it might be best for me to do more research and make sure this isn't an anomaly just specific to your server. So in the short term, I do think it's best to set the rootURL manually in the /index.php file. But will do more research here, unless anyone else knows if this is a known situation on some servers. Thanks for the debugging you did in finding this.

Link to comment
Share on other sites

:D

I was just editing to say I'd hacked it to get it working.. thanks..

Heres my $_SERVER  contents:

[PATH] => /sbin:/usr/sbin:/bin:/usr/bin
    [sERVER_ADMIN] => support@register365.com
    [VSERVER_NAME] => Hosting
    [sERVER_PORT] => 80
    [AUTH_TYPE] => Basic
    [sERVER_PROTOCOL] => HTTP/1.1
    [GATEWAY_INTERFACE] => CGI/1.1
    [sERVER_SOFTWARE] => Zeus/4.3
    [sCRIPT_FILENAME] => /content/Hosting/l/a/lab.digimute.com/web/test.php
    [REQUEST_METHOD] => GET
    [REQUEST_URI] => /test.php
    [QUERY_STRING] => 
    [sCRIPT_NAME] => /test.php
    [REMOTE_HOST] => 192.165.126.74
    [REMOTE_ADDR] => 192.165.126.74
    [REMOTE_USER] => 
    [CONTENT_LENGTH] => 0
    [DOCUMENT_ROOT] => /content/Hosting/l/a/lab.digimute.com/web
    [sERVER_NAME] => lab.digimute.com
    [REDIRECT_URL] => /test.php
    [REDIRECT_STATUS] => 200
    [REDIRECT_PATH] => /content/Hosting/l/a/lab.digimute.com/web/test.php
    [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8
    [HTTP_COOKIE] =>__utma=191603903.1810433341.1284657176.1295275992.1295476766.50; X-Mapping-enlokcai=778709DDDA960FBE6B9A70D95DACA463; wire=59eda345a66f5af2ebbc193d855561c9; wire_challenge=5b30e1db7ff942af8b7ac43a106d5634
    [HTTP_HOST] => lab.digimute.com
    [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch
    [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10
    [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.3
    [HTTP_ACCEPT] => application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    [HTTP_CONNECTION] => keep-alive
    [HTTP_CACHE_CONTROL] => max-age=0
    [ORIG_SCRIPT_FILENAME] => /usr/local/php5/bin/php-cgi
    [ORIG_PATH_INFO] => /test.php
    [ORIG_PATH_TRANSLATED] => /content/Hosting/l/a/lab.digimute.com/web/test.php
    [ORIG_SCRIPT_NAME] => /php5-cgi/php-cgi
    [php_SELF] => /test.php
    [REQUEST_TIME] => 1295628848
    [argv] => Array
        (
        )

    [argc] => 0

Again probably something to do with the Zues server...

Thanks for the help on this...

Mike.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...