PDA

View Full Version : [fixed] htaccess and 2 plus domains


Zachariah
02-28-2017, 03:09 AM
I wanted to run some ideas by the community and seek some advice on setup and settings. On a shared host plan there are 2 domains on the same package (max 10). I was thinking of changing the file layout to redirect requests to subfolders. It seems less messy on the FTP side as the account approaches 10 domains with their own file structure and content.

Current Cpanel layout:

Doamin1.com is the main domain.
Domain2.com is a add-on domain (max 10)


Current file locations were setup:

domain1.com => /public_html
domain2.com => /public_html/site2


Desired layout of file structure:

.htaccess => /public_html
domain1.com => /public_html/site1
domain2.com => /public_html/site2


Future as domains are added:

domain3.com => /public_html/site3
domain4.com => /public_html/site4
domain5.com => /public_html/site5
domain6.com => /public_html/site6
domain7.com => /public_html/site7
domain8.com => /public_html/site8



Are there any htaccess configurations that come to mind that could make this workout ?

Thank You.

--------------- Added 1488317132 at 1488317132 ---------------

It was quite easy once you think about it.

Point all domains to the web accounts single public web folder via CPanel domain tools.


site1.com => /public_html
site2.com => /public_html



Create a .htaccess file in /public_html that will push requests to the correct subfolders where each website is contained.

EX:

site1.com => /public_html/site1
site2.com => /public_html/site2



Options +FollowSymLinks

RewriteEngine on
#================================================= ================================
# FIRST Handle the http requests first before removing the additional url junk
#================================================= ================================

#rule for site1.com to link to site1folder directory
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteCond %{REQUEST_URI} !^/public_html/site1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site1/$1

#rule for site2.com to link to site2folder directory. Its the same as above just with site2 URL and sub-folder
RewriteCond %{HTTP_HOST} ^(www.)?site2.com$
RewriteCond %{REQUEST_URI} !^/public_html/site2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site2/$1

#================================================= =========
# SECOND Remove the additional url junk once the new url is loaded
#================================================= =========

#rule for site1 url rewrite to remove /site1folder/index.php from the URL
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteRule ^(/)?$ site1/index.php

#rule for site2 url rewrite to remove /site2folder/index.php from the URL. Again its the same as above just with the site2 URL and sub folder info.
RewriteCond %{HTTP_HOST} ^(www.)?site2.com$
RewriteRule ^(/)?$ site2/index.php

This can be done repetitively to add more domains to the server.