transforming domain names to querystring params.

Topics: Developer Forum, User Forum
Sep 27, 2010 at 8:54 AM


I tried the below INI File

RewriteEngine ON
RewriteLog c:\inetpub\iirfLogs\iirf
RewriteLogLevel 1
StatusInquiry ON
CondSubstringBackrefFlag *

RewriteCond %{HTTP_HOST} ^(?!www)([^.]+)\.mydomain\.com [I]
RewriteRule ^/(.*)$ /mypage?host=*1 [U,L]

I have a requirement like this

Suppose a user types in
I need to forward the subdomain as parameter to

When i try like this

RewriteRule ^/(.*)$ /folder/index.html?host=*1 [U,L]
The parameter is not getting passed.
Kindly help me to achieve this.


Oct 1, 2010 at 1:32 AM
Sha, turn on iirf logging, and run one request through the filter. Examine the lotto see what is happenning. You can post the logfile here if you'd like some help analyzing it. Good luck.
Oct 1, 2010 at 4:05 AM

Hi Cheeso,

Thanks for the reply.

I truned on logging, I was able to figure it out ,, now its working.

Its working when there is no www prefix enetered in the address bar.

I need to get it work for even when www is entered along with the sub domain.

Example :

If I type in , it should forward to

Also when i type in , it should forward to

Could you please tell me the rewrite rule for this condition ?


Oct 1, 2010 at 2:27 PM
Sha, the part in the pattern in the RewriteCond that reads (?!www) specifically excludes domains that begin with www. You need to eliminate that part in the pattern in order to allow domains with www. If you want to try out different regex's, use the tools I described in the documentation. There's a regex tester tool I think called "Regex" . There's a link to it in the iirf doc. Check it. Good luck.
Oct 1, 2010 at 5:16 PM

Hi chesso,

I tried with a different condition.

Only either of the condition is working, but for me it should work for both with www and without www.

Frankly I am not an expert in regex , If you could help me out with rewrite condition, it would be great of you.

I am reading the documentation and trying out from past few days


Oct 4, 2010 at 2:46 PM
As i said in my previous reply, you need to Remove the (?!www) to match domain names including www.
Oct 15, 2010 at 1:11 PM


You can delete the www and you will get what you want:

RewriteRule ^www\.(.*)$ $1 [NC]

Put this line in advance to your actual rules and anything coming with the www prefix will lose it



Oct 15, 2010 at 1:23 PM

No, that's not right, erill.  The www appears in the host name, not in the URL.  If you refer to www in a regex pattern in the RewriteRule, then you are matching on the URL, not the hostname.  Your suggestion is wrong and potentially confusing.

Sha1 is using the substring www in in the context of a RewriteCond.  What I told him was to remove the (?!www) in the RewriteCond, and that will solve his stated problem. My answer was correct.


Oct 15, 2010 at 1:45 PM

You are right again. Sorry. I better stay quiet...