Redirect every subdomain of one domain to another domain

Using a single web hosting account to host multiple sites

Redirect every subdomain of one domain to another domain

Postby Jak-S » Tue Aug 29, 2006 7:20 am

Hi, i am trying to redirect every sub domain for one domain to the identical sub domain on another domain, like this:

http://getelementby.com > http://getelementsby.com
http://www.getelementby.com > http://www.getelementsby.com
http://test.getelementby.com > http://test.getelementsby.com
etc.

I have this rule, but for some reason it always redirects to http://getelementsby.com, regardless of any sub domain you type in (such as http://www.getelementby.com). Any ideas?

Code: Select all
RewriteCond %{HTTP_HOST} ^(.*)getelementby.com$
RewriteRule ^(.*)$ http://%1getelementsby.com/$1 [R=301,L]


Thanks in advance,
Jack
Jak-S
 
Posts: 5
Joined: Tue Aug 29, 2006 7:16 am

Postby richardk » Tue Aug 29, 2006 9:07 am

Works fine for me. Clear your browser's cache, maybe you have old redirects cached.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Jak-S » Tue Aug 29, 2006 9:14 am

Ha! Now i feel stupid. Thanks, works fine :).
Jak-S
 
Posts: 5
Joined: Tue Aug 29, 2006 7:16 am

Postby Jak-S » Tue Aug 29, 2006 9:18 am

Actually, just another quick question, is it possible to change it so that it will redirect any domain that isn't getelementsby.com, rather than just getelementby.com. I tried this but it didn't work:

Code: Select all
RewriteCond %{HTTP_HOST} !^(.*)getelementsby.com$
RewriteRule ^(.*)$ http://%1getelementsby.com/$1 [R=301,L]
Jak-S
 
Posts: 5
Joined: Tue Aug 29, 2006 7:16 am

Postby richardk » Tue Aug 29, 2006 9:50 am

This won't work for two part tlds (eg .co.uk):
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# no subdomain
RewriteCond %{HTTP_HOST} !^(.+\.)?getelementsby\.com$  [NC]
RewriteCond %{HTTP_HOST} ^[^\.]+\.[^\.]+$
RewriteRule ^(.*)$ http://getelementsby.com/$1    [R=301,L]

# with subdomain
RewriteCond %{HTTP_HOST} !^(.+\.)?getelementsby\.com$  [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.[^\.]+\.[^\.]+$
RewriteRule ^(.*)$ http://%1.getelementsby.com/$1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 50 guests

cron