Ok, so I figured it out. The problem was that on my local machine and on my other server I was not at the root domain so I was using $_SERVER['SCRIPT_NAME'].DIRECTORY_SEPARATOR."js/"
to determine the root url to make an alias to the js files path. This returned /app/js/
. This worked fine when the files where in a sub folder from the domain somewhere e.g. domain.com/app/js/file.js
.
However once I was installing this app on my server and it was the root application $_SERVER['SCRIPT_NAME'].DIRECTORY_SEPARATOR."js/"
was returning //js/
. That was the problem! That is not the same as /js/
. That was bypassing the domain as part of the url and instead telling the browser to look at http://js
like it was a fully qualified url. I am assuming //
is shorthand for http://
though I've never tried this before.
To fix this I hacked together this function based off of something in the Yii Framework, which is what I'm using for this application.
function getBaseUrl() {
$scriptName=basename($_SERVER['SCRIPT_FILENAME']);
if(basename($_SERVER['SCRIPT_NAME'])===$scriptName)
$_scriptUrl=$_SERVER['SCRIPT_NAME'];
else if(basename($_SERVER['PHP_SELF'])===$scriptName)
$_scriptUrl=$_SERVER['PHP_SELF'];
else if(isset($_SERVER['ORIG_SCRIPT_NAME']) && basename($_SERVER['ORIG_SCRIPT_NAME'])===$scriptName)
$_scriptUrl=$_SERVER['ORIG_SCRIPT_NAME'];
else if(($pos=strpos($_SERVER['PHP_SELF'],'/'.$scriptName))!==false)
$_scriptUrl=substr($_SERVER['SCRIPT_NAME'],0,$pos).'/'.$scriptName;
else if(isset($_SERVER['DOCUMENT_ROOT']) && strpos($_SERVER['SCRIPT_FILENAME'],$_SERVER['DOCUMENT_ROOT'])===0)
$_scriptUrl=str_replace('\\','/',str_replace($_SERVER['DOCUMENT_ROOT'],'',$_SERVER['SCRIPT_FILENAME']));
else
throw new Exception('The App is unable to determine the entry script URL.'));
return rtrim(dirname($_scriptUrl), '\\/');
}
I hope this helps someone else.