views:

44

answers:

2

I have a primary domain - let's call it xyz.com. I also have several other secondary domains such as abc.com def.com, ghi.com, etc.. These domain all have the same content.

I am trying to do a URL redirect in IIRF that will take any of the secondary domains, and replace it with my primary xyz domain.

This is the closest I have gotten.

RewriteCond  %{HTTP_HOST}  ^(?!(.*)\.xyz\.com)$
RedirectRule ^/(.*)$        http://*1.xyz.com/$1   

Problem #1: with this if I navigate to 123.abc.com, I am brought to .xyz.com (I am losing my sub-domain, I thought I could retrieve that with '*1').

Problem #2: even when I go to www.xyz.com, I am redirected to .xyz.com this rule should obviously ignore any xyz.com domain

+1  A: 

this should work

#not in main.com
RewriteCond %{HTTP_HOST} !.*main.com [NC]
#get the subdomain as a backreference to use in the RewriteRule
RewriteCond %{HTTP_HOST} (.*)[a-z0-9]+\.[a-z]+$ [NC]
#Rewrite the new URL
RewriteRule ^(.*)$ http://%1main.com/$1 [NC,QSA,L]

I'm not the most uber regex guru though, so there may be some border cases which provide unexpected results

jay.lee
Im really going for a Redirect here. Can I just substitute RedirectRule for RewriteRule?
Dutchie432
ohh, my bad, I saw RedirectRule as RewriteRule. In any case, add `R` to the flags at the end of the RewriteRule to use a redirect instead. You can even specify an HTTP redirect code eg. R=301
jay.lee
The regEx is not quite right. I got "?!" means "not". Right now I am not getting any effect with your code in place...
Dutchie432
http://cheeso.members.winisp.net/Iirf20Help/html/e013a406-9f3a-4385-b986-6c4c410dad48.htm
Dutchie432
Up-voted for your effort. Was able to get a direct answer from the developer. http://iirf.codeplex.com/Thread/View.aspx?ThreadId=226802
Dutchie432
A: 

I took me a week, but I got it.

##### handles 3-part domains like "xxx.yyy.com"
    RewriteCond %{HTTP_HOST} ^(.*)\.(?!xyz).*\.com$        
    RedirectRule ^/(.*)$ http://*1.xyz.com/$1 [R=301]

and

##### handles 2-part domains like "yyy.com"      
    RewriteCond %{HTTP_HOST} ^(?!xyz).*\.com$        
    RedirectRule ^/(.*)$ http://xyz.com/$1 [R=301]
Dutchie432