On shared web-hosting my software supports multiple domains (all domains point to the same public_html root directory).
What I want to do is keep redirects (and any RedirectMatch) in their own host specific/dedicated .htaccess file.
Visually the directory structure looks like this…
/public_html/ (all domains are pointed internally to this directory)
/public_html/.htaccess
/public_html/www.example1.com/
/public_html/www.example2.com/
/public_html/www.example3.com/
There are two approaches I’m considering though would appreciate input from others:
The first would be to keep domain specific redirects out of the main .htaccess file as defined above. So I’d like to have redirects handled by the .htaccess files as defined by below if possible…
/public_html/www.example1.com/.htaccess
/public_html/www.example2.com/.htaccess
/public_html/www.example3.com/.htaccess
…if this is not feasible I’ll settle for a rewrite to a PHP file to hand off redirects to PHP instead. I imagine this isn’t as performance oriented though on the other hand it would give me the opportunity to log redirects and see how long it takes them to level off.
Some clarifications:
-
I’m using shared web hosting so anything Apache related needs to be done through .htaccess files only.
-
There are no redirects/matches in the master .htaccess file nor will there ever be since two domains may eventually attempt to use the same redirect.
Since you are on shared host, You cannot afford to have any solutions concerning conf files (which BTW are better). So wont bother to list them. Best way to do the above is like this:
The code was written keeping in mind that none of the domains share any kind of file/data on the server. Every file/data pertaining to a domain is kept under a folder having the name equal to its domainname.
The code below is tested(both static and non static):
And add either of the following to the above:
for doing it statically:
for doing it statically: and also if you want to access the site without
wwwfor Non-statically do it: this is a better sol
All the above will do is redirect URI to their specific domain’s folder. All other domain specific rewrites can be handled in the respective folders.
If you have URIs without the www, i.e.
example1.comchange^www\.(example1|example2|example3)(\.com)$to^(www\.)?(example1|example2|example3)(\.com)$