Forum Moderators: phranque
I have domain.com, domain2.com, and domain3.com - for simplicity, lets forget about domain3.com
They are setup as follows
domain.com
domain.com/domain2
domain2.com was added using CPanel and the Add-On Domain Feature.
I noticed that in domain.com/domain2 - there was an .htaccess file that did not have an "edit" option, and showed up as a blank document. I have removed it.
I am currently using the following in the .htaccess file in the domain.com root directory.
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L] I have tried repeating the above for the other domains in the same file, but have ran into problems - as I anticipated.
Currently it works as follows:
http://domain.com => http://www.domain.com
http://domain2.com => self
http://domain2.domain1.com => self
http://www.domain2.domain1.com => self
The goal is:
http://domain.com => http://www.domain.com
http://www.domain.com => self
http://domain2.com => http://www.domain2.com
http://www.domain2.com => self
http://www.domain2.domain.com => http://www.domain2.com
http://domain2.domain.com => http://www.domain2.com
http://www.domain.com/domain2 => http://www.domain2.com
http://domain.com/domain2 => http://www.domain2.com
I'm not sure of if I need to re-create the .htaccess file in domain/domain2, or if it can all be done from the root directory of "domain"
Any help would be greatly appreciated. If I was using a brail keyboard, my face would say fdsaljk fdlsk fdadfla - as I have been smashing it against the keyboard for the better part of the day in regards to this issue.
Thanks for the read folks - looking forward to your expert advice.
[edited by: jdMorgan at 11:10 pm (utc) on Nov. 1, 2005]
[edit reason] Removed specific URLs & de-linked. [/edit]
Yes, that may be the easiest solution here.
.htaccess files are only executed for a request in the filepath corresponding to the requested URL-path. That is, if the domain domain2 is DocumentRooted in directory /domain1/domain2, then an .htaccess file in directory /domain1 will not be processed for requests to domain2; It would only be precessed if domain domain2 was also rooted in directory /domain1.
The other alternative is to delete the "add-on" domain, and instead define it as a "alias" domain. This points requests for domain2 to /domain1's root directory, leaving it up to you to sort out the requests by using the requested HTTP_HOST header, for example, using mod_rewrite. In other words, it's then up to you to 'map' domain domain2 requests to the directory /domain1/domain2 or some other subdirectory using something like this simple example:
RewriteCond %{REQUEST_URI} !^/domain2
RewriteCond %{HTTP_HOST} ^(www\.)?domain2
RewriteRule (.*) /domain2/$1 [L]
Note that your control panel may have a different name for the 'alias' term I used above -- many of them are different, and use terms designed to make users comfortable rather than to have any standard or accurate technical meaning.
Frankly, I think you may find it a lot easier to just replicate the .htaccess code into your add-on subdirectories, rather than going the do-it-yourself domain-to-subdirectory-mapping route I describe.
It often helps to remember that domains and URLs are different from servers and filepaths. Some time spent with mod_rewrite makes clear the fact that a URL need not have anything in common with a filepath, and indeed, that some things that look like 'files' in URLs are actually scripts generating dynamic content, and not files at all.
Jim