(.htaccess) Mapping Multiple Domains to a different folders

Imagine if your have multiple domains with multiple sub folders and you’re using the root directory (public_html) as your main domain. Isn’t messy?

Try this tricks using your .htaccess.

  1. In root (public_html) directory, create a folders folder1 and folder2.
  2. Create .htaccess  in your public_html  directory.
  3. Paste the following rules and modify accordingly.
<IfModule mod_rewrite.c>
RewriteEngine On

# pointing domain1.com to folder1
ReWriteCond %{HTTP_HOST} domain1.com
ReWriteCond %{REQUEST_URI} !folder1/
ReWriteRule ^(.*)$ folder1/$1 [L]

# pointing domain2.com to folder2
#ReWriteCond %{HTTP_HOST} domain2.com
#ReWriteCond %{REQUEST_URI} !folder2/
#ReWriteRule ^(.*)$ folder2/$1 [L]

</IfModule>

Note: If you have working sub domains, you might need to manually point them to your index file by creating .htaccess inside your sub domain directory. If you have existing .htaccess then add this line:

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

 

 

Leave a Reply

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