Some information:
If a user navigates to "http://www.domain1.com/" the files in folder "/home/myaccount/public_html/" will be viewed (This is the top level folder for html. All other domains are sub-folders of this directory).
SOP with my hosts, too.
If a user navigates to "http://www.domain2.com/" the files in folder "/home/myaccount/public_html/domain2/" will be viewed.
Ditto - and this will bypass domain1's .htaccess file.
If a user navigates to "http://www.domain1.com/domain2/" the files in folder "/home/myaccount/public_html/domain2/" will also be viewed.
Ditto - except that .htaccess from domain1 will be processed THEN the .htaccess in domain2. This is the only way that both .htaccess files will be read.
If a user navigates to "http://forums.domain2.com/" the files in folder "/home/myaccount/public_html/domain2/forums/" will be viewed.
Thank you, I think I had assumed this was the case (or wondered about a subdomain on a subdomain [addon domain]).
If a user navigates to "http://www.domain2.com/forums/" the files in folder "/home/myaccount/public_html/domain2/forums/" will also be viewed.
As should be the case.
***********************************************************
Goal 1:
If a users navigates to "http://www.domain2.com/forums/", I want them redirected to "http://forums.domain2.com/". In folder "/home/myaccount/public_html/domain2/" I have placed the following .htaccess file and it works as desired (although at your suggestion, I will remove the unnecessary lines).
You've got it!
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain2\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$
RewriteRule ^forums\/?(.*)$ http://forums.domain2.com/$1 [R=301,L]
# no need to escape /'s in the regex
***********************************************************
Goal 2:
If a user navigates to "http://www.domain1.com/domain2/" I want them to receive the forbidden error. The good guys (members of the club) know the proper URL. The bad guys use "http://www.domain1.com/domain2/". The only acceptable way to get to directory "/home/myaccount/public_html/domain2/" is to navigate to "http://www.domain2.com/". I want this so I can keep my statistics accurate. If they navigate to "http://www.domain1.com/domain2/" then this access is listed in the domain1 log instead of the domain2 log. In folder "/home/myaccount/public_html/" I have placed the following .htaccess file
Ah! The missing "goal" from above. In that case, you've gotten this correct, too (except for "optimizing" the RewriteCond statements and escaping the /). {Duh - see below.}
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain1\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain1\.com$
RewriteRule ^domain2\/?(.*)$ - [F]
This part works properly if the .htaccess file associated with Goal 1 is not present in folder "/home/myaccount/public_html/domain2/". As soon as the Goal 1 .htaccess file is added, the user no longer receives the forbidden error.
Okay, I see that the (escaped) / is optional AND that you're allowing more in the {REQUEST_URI}. Why? If all you're doing with this RewriteRule, you have no need of anything beyond domain2/ in the regex. If, for some weird reason (server configuration?) this does not merely return a 400 (bad request), 401 (unauthorized), 403 (forbidden), 406 (not acceptable) ..., replace the - [F] with an absolute redirection to another domain - or your own DocumentRoot (domain1).
***********************************************************
There must be some interaction between the two .htaccess files that is causing the problem or else I am violating some apache rule.
.htaccess files do not interact. The logic used in one file may impact the logic of the other but only if the redirection gets to the other's directory. .htaccess is a file structure configuration file and can only be read if its directory is in the path of the request and only in order (from DocumentRoot to the requested file's directory.
Bookmarks