Move website from root directory to subdirectory by .htaccess

Well known web hosts like hostgator does not allow moving your primary domain to a different subdirectory. The problem is that you will have cluttered all the primary domain's file onto the public_html  and you are searching for a solution which will move the root to a subdirectory without visibility of the foldername in url. This is a very common scenario and can be done by modifying .htaccess of public_html.If it doesn't exists create it !
RewriteEngine on
RewriteBase /

RewriteRule  ^$ subfolder/    [L]
RewriteRule  (.*) subfolder/$1 [L]
This is a very very generic approach.A more productional approach is to use this.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ 
RewriteRule ^(/)?$ subdir/index.php [L]
Line by line more specifically, RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$  tells that only domain to use is mydomain.com.Substitute this with your domain name. RewriteCond %{REQUEST_URI} !^/subdir/ tells that if the rule does not apply if the request has a subdirectory specifically mentioned. RewriteCond %{REQUEST_FILENAME} !-d  RewriteCond %{REQUEST_FILENAME} !-f  are pitty common which tells do not apply if the file directory exists do not apply this rule. RewriteRule ^(.*)$ /subdir/$1  Every condition that matched the rule now apply this,  starting with anything will be forwarded to subdir. RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$  Check for the condition that the request is for only domain name. RewriteRule ^(/)?$ subdir/index.php [L]  Forward the request to index.php page in subdirectory.