Move website from root directory to subdirectory by .htaccess

Swapnil
No Comments

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 !

This is a very very generic approach.A more productional approach is to use this.

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.

Leave a Reply

Search

Powered by Ajaxy