So I have 2 sites, just call them example.com
and admin.example.com
.
example.com
is listed in my cPanel with the document root being /home/username/public_html (unchangeable), but the actual file is stored in home/username/example-site.admin.example.com
is listed with document root home/username/public_html/admin.
Directory structure:
home/username
|- example-site
|...
|- public_html
|- admin
Those 2 sites were built with different framework. And now, without a proper .htaccess file, when I try to access example.com
it shows lists of files in the public_html folder, and admin.example.com
works fine.
Therefore, I'm trying to move my document root for example.com
from /home/username/public_html to /home/username/example-site with a .htaccess file, but I can't seem to find a proper format to suit my need. Any ideas?
CodePudding user response:
I suggest that you move the folder "example-site" into the folder "public_html" (you might also want to rename it):
home/username
|...
|- public_html
|- example-site
|- admin
Then you implement a rewriting rule that maps all requests that do not specify the admin subdomain as http host into that folder:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^admin\.example\.com$
RewriteCond %{REQUEST_URI} !^/example-site/
RewriteRule ^ /example-site%{REQUEST_URI} [L]
As an alternative you can also implement a positive condition:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteCond %{REQUEST_URI} !^/example-site/
RewriteRule ^ /example-site%{REQUEST_URI} [L]