Redirecting a Domain into a Folder

There are a lot of web hosting providers these days who allow you to host multiple domains on the one hosting account. Often these extra domains point to folders within your hosting with each of the extra domains using a different folder. Some hosting treat the first domain you use with the hosting differently from the ones that you add afterwards (lets call this the main domain for the account). Often your main domain points directly to the public_html or www folder of your hosting while the extra domains all point to folders within that folder.

Having this sort of setup for their hosting accounts provides those people who only use the account to host one domain with the benefit that they have one less folder to go down through to get to where their site is stored on their hosting. It has a disadvantage for those who have multiple domains on their account in that one domain is treated differently from the rest. We also end up where and may both access the same site. Also if you ever need to give someone FTP access to work on the main domain then they would have access to all the other domains as well.

Where the web hosting is using Apache web server we can move our main domain into a folder so that it is treated exactly the same as the other domains on our hosting account. We do this by first setting up a folder to hold the main domain and copying all of the files for our main domain to there.

The next step is to add some code to the .htaccess file in the public_html or www folder that is the root folder of what appears on the internet that will redirect all requests for pages on the main domain to the appropriate pages within the folder we copied them to. If our domain is "" and the folder we have moved it to is "subfolder" then the code we would have in the .htaccess would look like this (just change the references to your real domain and folder names). Oh and if your default page is something other than index.html you'll need to change that too.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?$ [NC]
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?$ [NC]
RewriteRule ^(/)?$ subfolder/index.html [L]

Once this code is in place you can then delete the originals of all the files that you copied and your visitors will continue to see the site without having any idea that you have moved it into a folder.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow