.htaccess redirect your main site to a specific sub folder without showing sub folder name from URL bar

Normally, the root directory is under public_html where you upload your main site. But in my case since i have multiple sites and to keep my root directory clean as possible. With this technique through .htaccess you may able to redirect your main site to a certain sub folder without showing the sub folder name from the URL bar.

Reminders: If you have your current working site make sure to back up everything before starting.

  1. (if you have running site) move everything to a sub folder you have created public_html/yoursubfolder
  2. create .htaccess under public_html
  3. Then copy the following rules and save.
RewriteEngine On

RewriteCond %{THE_REQUEST} /yoursubfolder/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!yoursubfolder/).*)$ yoursubfolder/$1 [L,NC]

Leave a Reply

Your email address will not be published. Required fields are marked *