If you are new to hosting or if you already have web space somewhere, one of the headaches one usually faces is to manage different folders in the root folder. As the time passes by, the number of folders keeps increasing. If your host supports multiple domains on the same websapce, the problem could become even worse.
This usually happens if you try to install a CMS or forum to your root directory (Public_Html) and have other folders lying around in same directory. A clean solution to this problem is to make use of apache’s mod_rewrite module and redirect your root directory to a sub directory on your website.
# Turn on rewrites.
RewriteEngine on
# Only apply to URLs on this domain
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
# Only apply to URLs that aren’t already under folder.
RewriteCond %{REQUEST_URI} !^/folder/
# Don’t apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all those to insert /folder.
RewriteRule ^(.*)$ /folder/$1
# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ folder/index.php [L]
Copy the above code to your .htaccess file. The beauty of this approach is, all urls will remain the same. It wont have the subdirectory as a part of the sites url.









