Reputation: 1442
Is it possible to mirror a directorys content using apache htaccess files? I'm on virtual hosting with cpanel so don't have root access and want to avoid having two copies of the same files on my hosting account. What I am trying to do is to have two subdomains for example:
files.abc.com files.123.com
abc.com and 123.com would be seperate websites with differen't html, but when you visit the files subdomain they would be identical. I want the files subdomain to show the same directory if you get what I mean? Any other suggestions of how this could be achieve would be appreciated. Thanks in advance.
Upvotes: 1
Views: 1530
Reputation: 143906
It depends on how you have the 2 domains setup and your hosting. One straightforward way of doing this without knowing any of the details is to point one to the other using an internal proxy, by putting this in the .htaccess file of the other domain (where files.abc.com is being hosted):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^files\.abc\.com$ [NC]
RewriteRule ^(.*)$ http://files.123.com/$1 [P,L]
Here, we have files sitting in the host for files.123.com
, meaning we can go to http://files.123.com/some/file.txt. But with this rule, you can go to http://files.abc.com/some/file.txt and it will internally proxy to the 123.com host.
If both are domains are pointing to the same host, and say, you have either a rule or a cpanel subdomain setup for 123.com:
RewriteCond %{HTTP_HOST} ^files\.123\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /here-are-where-123.com-files-really-are/$1 [L]
Or some equivalent setup in cpanel. Either way, say requests for files.123.com
are served by the directory /here-are-where-123.com-files-really-are/
. You'd simply need to include a set of rules to accommodate for the other files domain and put them in the .htaccess file in your document root:
RewriteCond %{HTTP_HOST} ^files\.abc\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /here-are-where-123.com-files-really-are/$1 [L]
Upvotes: 1