Forum Moderators: phranque
I have multiple domain names that are hosted on the same space. Can someone show me the code I'd need to use for an htaccess redirect to do this:
Let's say my primary website is www.colors.com. I also own www.red.com, www.blue.com, etc. These pages all go to the same page (www.colors.com).
If a user went to www.red.com, I'd like them to be redirected to www.colors.com/red.html ... is this possible?
Thanks a bunch again.
RewriteCond %{HTTP_HOST} ^www\.red\.com [NC]
RewriteRule ^(.*) [colors.com...] [L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.[^.]+\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.([^.]+)\.com /$1.html Modified from here: [engelschall.com...]
/claus
Redirect /index.html [colors.com...]
Or
RedirectPermanent /index.html [colors.com...]
Both of them should work!
Open .htaccess in the document root folder of www.red.com and add this line:Redirect /index.html [colors.com...]
Or
RedirectPermanent /index.html [colors.com...]
Both of them should work!
Well, these URLs all point to the same page. I only have one account with my webhost, and several URLs that point to the same page. So I believe that either of those would make ALL of the URLs point to the /red.html page, instead of redirecting only users who are using red.com's url.
I can't change the .htaccess file only for red.com because there is only one .htaccess file for all of the URLs. :)
They can do this in a variety of ways. How, exactly, do they "point to"?
I suspect the reason why the htaccess redirects do not work is because you have a redirect taking place before this one is supposed to kick in. Or, are the domains "red.com" etc. showing your original domain inside a frame? These are important details.
/claus
However, there are no frames involved. This is what I did: I set up hosting / primary domain name. I FTPed my website. I then modified the DNS for the other domains to go to my host's nameservers, and then contacted my webhost and told them I had several other domains that I needed to go to the same page. They replied that they needed to alias the other domains to my main account, and then hooked it up for me. That's as in-depth as my knowledge about how that works gets. Sadly. =)
I recently contacted them about getting this to work like I wanted, and got a reply with a suggestion for a javascript redirect (which also didn't work).
Thanks for the help, guys. As the lone "web guy" at my corporation, I definitely appreciate it.
>> javascript
The bad thing about this is that it will only work for users that have enabled javascript. It will not work for search engines. Anyway, this one could do it, just place it in the <head> section of your index page:
<script type="text/javascript"><!--
var A = 'http:\/\/www.red.com\/'
var Z = 'http:\/\/www.domain.com\/red.html'
if (window.location.href == A) window.location.href = Z;
//--></script> I really hope this one will work. It checks if the browser address bar says "www.red.com" and if it does, it redirects to "domain.com/red.html".
/claus
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} red\.com [NC]
RewriteRule .* http://www.colors.com/red.html [R=301,L] I don't think it can be done any simpler than that. The code checks if the host name contains "red.com" and if it does, all requests are directed to "colors.com/red.html". "R=301" tells the Search Engines that "red.com" is permanently moved to the other address (so they will not think it's duplicate content)
I suppose that you have uploaded the .htaccess file to the root of "colors.com" and that the root of "colors.com" and "red.com" is the same.
/claus