I’ve had two problems with my website that have been bugging me for a long time. The first was that when I tried to change to PHP5, I couldn’t use <?php include()?> to include files. That was because PHP5 disables register_globals, and I was using $DOCUMENT_ROOT to ensure that the includes worked regardless of the directory of the document requesting the includes file.
The second issue I was having was that when I created a subdomain, my host asked me to choose a directory I wanted the subdomain to use. For example, alex.asolis.net is located at asolis.net/alex. However, if someone went to the latter site, they would get a bunch of error messages since the $DOCUMENT_ROOT code made the document look for the includes file in the asolis, rather than the alex, directory. While alex.asolis.net still worked, asolis.net/alex had a bunch of error messages because the includes files it was looking for didn’t exist.
After several past failed attempts to find a solution to these issues, I finally figured them both out yesterday.
All I had to do to fix the includes problem was replace $DOCUMENT_ROOT with $_SERVER['DOCUMENT_ROOT'] (and put AddType x-mapp-php5 .php in the .htaccess file, of course).
The subdomain issue was equally simple. All I had to do there was add this to the .htaccess file in the asolis directory:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^alex\.asolis\.net$ [NC]
RewriteRule ^alex(.*)$ http://alex.asolis.net$1 [R=301,L]
That results in a 301 redirect from, for example, asolis.net/alex/file.html to alex.asolis.net/file.html.
It’s that easy!
