Forum Moderators: phranque
The situation is that one of my hosting accounts allows multiple dns but only one "space". The primary site hosted there uses only 5% of the bandwidth and even less of the storage and it never will use more than that by design.
I have a directory set up with content more suited to a "stand alone" site and have secured an appropriate domain name. Rather than set up another hosting account I'd rather pinch pennies and simply utilize the "excess" on the existing account.
In order to prevent dupe content penalties I'd like to use htaccess to direct requests for www.domainA.com to the www.domainA/domainA/ directory and requests coming for www.domainB.com to the www.domainB.com/domainB/ directory.
My searches so far seem to indicate that this is possible but I haven't found exactly how to go about it.
Freq---
Could someone with a clue about htaccess (obviously not me) please confirm if this will work. The main site is currently getting spidered heavily so I can't risk taking it down with a major blunder.
Thanks in advance,
Freq---
Instead, use mod_rewrite to add the subdirectory name to the requested filepath internal to the server only.
There are a lot of threads here about mapping multiple domains into the filespace of a single domain, so you might want to try a search.
Jim
Other than long "ugly" urls is there any disadvantage to doing as I had originally planned with regards to SEO or risk of a penalty from the engines for not having anything in the root (other than a robots.txt and an htaccess file)?
Thanks for your help. I will continue searching until I find exactly what I need. I'm sure it's in a thread somewhere.
Freq---
Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteCond $1!^domainA/
RewriteRule (.*) /domainA/$1 [L]
#
RewriteCond %{HTTP_HOST} ^(www\.)?domainB\.com
RewriteCond $1!^domainB/
RewriteRule (.*) /domainB/$1 [L]
Search engines and visitors will be entirely unaware that two sites are hosted under the same account, unless they investigate the domain registrations and DNS records; the rewrite process itself is entirely transparent.
You can move everything, including a robots.txt file for each domain, into its own subdirectory; the only file needed in the home directory is this .htaccess file.
True HTTP/1.0 clients do not provide a host header. For this reason, a default rewrite (to domainA) is provided above. While many clients advertise that they are HTTP/1.0, most have been modified to send the host header, since otherwise they cannot access any sites that are hosted on name-based virtual servers (Name-based servers depend on the HTTP host header to figure out which of the many sites at the same IP address to serve).
Since you've set up the DNS, the only concern is whether your server is set up to accept both domain names and send requests for them to your document root ('home' directory). If that's taken care of, then adding the above rules to your existing .htaccess file should do what you need.
The Apache forum Charter [webmasterworld.com] contains links to basic mod_rewrite documentation; To prevent trouble, look up each of the directives used in the code above, and make sure you understand how it works before trying to use it.
Jim
Since my last post I have been sifting through every doc and tutorial I could find.
What I had come up with so far isn't nearly as pretty as what you've provided so I will definately try yours first and just continue refining mine so that I have a fair understanding of what is really going on there.
Just to clarify another point. There is no reason I can't still host one of the sites at root and use the htaccess to re-write the other correct? Is there any conflict there that I'm not aware of?
Thanks again,
Freq---
It's a question of organization and portability. If you "mix" the domain-to-subdirectory .htaccess code with the other .htaccess code for one of the domains, and later decide to move or modify that domain, then you're left with the task of untangling the two files.
On the other hand, if you put each domain in it's own subdirectory, there's no intermixing in .htaccess, and the whole thing is a lot more uncluttered and easier to manage. The entire structure of each domain is then independent of the others, and 'portable' -- to move it to another server, the only work is in copying it.
Jim