Forum Moderators: phranque

Message Too Old, No Replies

htaccess redirecting question

what code to use for redirecting domain1.com to domain2.com/domain1.html

         

feenomenal

8:46 pm on Sep 18, 2003 (gmt 0)

10+ Year Member



Well, I tried asking a similar question here once before but I never got it working right, so I figured I'd try again. ;) Sorry for the rerun.

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.

bcolflesh

8:53 pm on Sep 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try:

RewriteCond %{HTTP_HOST} ^www\.red\.com [NC]
RewriteRule ^(.*) [colors.com...] [L]

feenomenal

9:01 pm on Sep 18, 2003 (gmt 0)

10+ Year Member



Thanks! I just tried that, but unfortunately it's still going to the index page. (in other words, www.red.com is still going to www.colors.com, and not www.colors.com/red.html).

Any other thoughts?

claus

9:04 pm on Sep 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Haven't tried this, but here's a good guess. It will not work for HTTP1.0, only HTTP1.1, according to Engelschall:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.[^.]+\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.([^.]+)\.com /$1.html

Modified from here: [engelschall.com...]

/claus

feenomenal

9:42 pm on Sep 18, 2003 (gmt 0)

10+ Year Member



Sadly, that one didn't do it either... Not sure what's wrong though since I don't really understand how the code works. :(

sitebuildit

2:21 am on Sep 19, 2003 (gmt 0)

10+ Year Member



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!

feenomenal

1:40 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



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. :)

feenomenal

1:41 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



And hell, I've been pulling my hair out over this one for so long I'd settle for a javascript redirect at this point. ;)

claus

1:52 pm on Sep 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> several URLs that point to the same page

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

feenomenal

2:16 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



Well, honestly I'm not sure how it works. I'm a designer moreso than a true webmaster, so the nitty gritty details are a little over my head.

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.

claus

4:06 pm on Sep 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps your account is not set up to be able to use .htaccess - your host will know this.

>> 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

feenomenal

4:29 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



.htaccess should be set up ... on another website (on the same host) I have a really uber-simple .htaccess redirect going to direct users to a page that I moved, and that one works.

I'll try that javascript code... many thanks!

claus

5:12 pm on Sep 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then, perhaps you just need to enable symlinks and turn on the rewrite engine. Try this modified version of the one bcolflesh posted:

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