IIRF Controlling the redirect of multiple secondary domains

Topics: Developer Forum
Sep 10, 2010 at 8:38 PM
Edited Sep 10, 2010 at 9:19 PM

I have a primary domain - let's call it xyz.com. I also have several other secondary domains such as: 




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

Any assistance would be greatly appreciated.

Sep 19, 2010 at 6:19 PM

You need to rework the RewriteCond to actually capture the first segment of the domain name. 

The current RewriteCond as written says "Any domain that DOES NOT match Something.xyz.com."   It is effectively a negated pattern, which means when the pattern evaluates to TRUE, there is no capture at all.  It evaluates to TRUE when there is no match.  See what I mean? 

You need to redesign that condition so that it evaluates to TRUE when it DOES capture.  Something like this: 

RewriteCond %{HTTP_HOST} ^(.*)\.(?!xyz).*\.com$

In English, that says "any domain that has three segments, where the middle segment is not xyz (and capture the first segment)."  

Using that RewriteCond, you'll have a proper *1 reference for use in the rule replacement string. 

Good luck.


Sep 20, 2010 at 1:49 PM
Edited Sep 20, 2010 at 4:12 PM

I've  been struggling with this for a week. RegEx is not my strong point. Great product! Thanks!!

PS - On a side note, this may be a good example to include in the example INI files. This is the final version I came up with

# redirect any secondary domain to a primary domain
# for a site with multiple domains pointing to the same location

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

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


Oct 1, 2010 at 2:12 AM
I'm glad it worked for you. I agree- your question would be a good example to include in the documentation.
Oct 1, 2010 at 2:14 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.