This is odd, but for some reason the $_SERVER[\"SCRIPT_URI\"] will not return the domain name when I am in child/sub-pages but will only work on the main page.
I was using $_SERVER[SCRIPT_URI] on my website http://www.a2zidx.com and a number of subdirectories like http://howto.a2zidx.com
I have had no problem with this for years and today got an error on a number of sites where $_SERVER[SCRIPT_URI] was not assigned. After contacting my isp they claim they have not made any changes but $_SERVER[SCRIPT_URI] no longer works. getenv('SCRIPT_URI') does not fail but returns a null string. Why this should happen suddenly after so many years I do not know. I ended up calling a function to go through various options to extract the filename which is what I wanted. Hope this covers everything. I had trouble including the function but checked "SCRIPT_NAME" "PHP_SELF" "SCRIPT_FILENAME "SCRIPT_URI"
Hope his helps.
If anyone knows why SCRIPT_URI would suddenly stop working I would love to know. The server is currently running Apache 2.4.