.htaccess Changing the document root from public_html to a subfolder

If you’ve ever needed to host your files for a site in a subfolder such as “public_html/mysubfolder/” as if it were “public_html/” so that your URL displayed is (for example) “http://www.epiphanydigital.com/” instead of “http://www.epiphanydigital.com/mysubfolder”, then you may want to try something like the following htaccess black magic:

RewriteEngine On
RewriteRule ^$ /mysubfolder/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/mysubfolder/
RewriteRule ^(.*)$ /mysubfolder/$1
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule ^epiphanydigital.com/(.*[^/])$ http://www.epiphanydigital.com/$1/ [R=301]

Now, a better way is to just modify your VirtualHost record directory on a site by site basis, but if you’re like me and you’re on a shared host, you just don’t have access to do this.  An .htaccess rewrite rule will cost slightly more overhead than a VirtualHost record.

Tags: , , ,


©2005-2017 Blog – Epiphany Digital is proudly powered by Badgers and Web Design is by Epiphany Digital
Entries (RSS) and Comments (RSS). 35 queries. 2.712 seconds.

Thank you for visiting this site. The web fairy will visit you in your sleep... you know, I was going somewhere with this, but it really doesn't have as much innocent charm as the tooth fairy, especially when I picture the web fairy as someone much like the Simpsons' Comic Book Guy but with wings. It's just not something I want.