Domain name change - 301 redirect to the new domain name

Topics: Developer Forum
Apr 4, 2011 at 4:27 PM


I want to take all visitors to the web site, and redirect them (with a 301 redirect) back to the website with the new domain name instead of the old one, regardless of what page they were trying to visit. I've been trying to get this to work in our development environment, but have had only a little bit of luck.

Our DEV environment consists of 2 runtime servers (called dev1 and dev2) which can be reached via the server name (ie:, or via the load balancer which uses

Visitor URL                               Redirected To    >>    >>    >>    >>


To make this happen, i have tried writing this into the IIRF.INI file on both of the runtime servers, but it's just not working. Can you tell me what i'm doing wrong?

RewriteLog E:\Program Files\IIS Log Files\iirf
RewriteLogLevel 2
IterationLimit 10
MaxMatchCount 10
RewriteEngine ON
StatusInquiry ON

RewriteCond %{HTTP_HOST}   ^dev\.ourdomainname\.ca$  [I]
RedirectRule ^.*$$1         [R=301]

RewriteCond %{HTTP_HOST}   ^dev1\.ourdomainname\.ca$  [I]
RedirectRule ^/(.*)$$1         [R=301]



Apr 4, 2011 at 5:49 PM

Well - for that first rule, you don't have any parenthesis in the regex pattern, which means you have no capture group.  Therefore when you put $1 in the replacement pattern, it refers to nothing.  I actually don't know what it will resolve to; you'd have to check the documentation, or the IIRF log.

The second rule seems like it would work, but it will never be used, because the first (broken) rule will always match every incoming request.

I think you need only ONE of those rules - the second one. 

Try it that way,  If it still doesn't work, set the LogLevel to 4, run ONE request through IIRF, and send me the log output.


Apr 4, 2011 at 6:43 PM
Edited Apr 4, 2011 at 6:44 PM

Hi Cheeso.

I commented out the first rule, and did some tests. These URL's worked:

Typed In Address Bar                                      Redirected To                   >>  >>


However, it still doesn't work if i visit the website using the load balancer at (notice the lack of a number after the "dev" virtual domain). I would use a wildcard and only have 1 rule, but when i want to do this in our production website, i will need 2 rules; One rule to handle the actual server name (ie: dev1), and another to handle the load balancer (which is the "dev" virtual domain in our DEV environment, but in production it is just "www").

Did you want a detailed log file, or is it just a case where my syntax is all wrong?

Apr 4, 2011 at 8:29 PM

I don't really get how the load balancer is changing things, but... all you need to do is insert an option in the RewriteCond to handle any hostname that people may use.  If dev, then add dev to the regex pattern.

Apr 5, 2011 at 1:25 PM

I am looking for help in writing a rule that will:

  • take any visitor our website that uses the URL * (where * is www, dev1, or dev2)
  • 301 redirect them to the new domain name * (where * is www, dev1, or dev2)
  • keep any requested page/folder in the new domain name.

I think i am close, but i'm having problems getting the regex rule to work. Can you help me figure it out.

Apr 7, 2011 at 2:04 PM

Unfortunatly i haven't been able to get this to work. I tried and tried, but it just wouldn't work.

It would have been nice if IIRF had some sort of rule builder or rule tester - at least then i might have had a chance to get it working.

I guess that would be a nice feature to add - a plain english rule builder. Maybe when they add it i'll come back and try it again. I'm afraid i have to abandon using IIRF, and i just can't recommend it.

Apr 7, 2011 at 2:04 PM

Try a regex like (dev|www|dev[0-9])\.domainname.zzz to match on various hosts in the RewriteCond.


Apr 13, 2011 at 2:46 PM

I would like to report that your regex worked, and has been working now for almost a week. Problem solved.

Thank you.

Apr 13, 2011 at 3:18 PM

Terrific, I'm glad it helped.  Thanks for the feedback.