Wildcard DNS Rewrite

Topics: User Forum
Jun 19, 2009 at 5:37 PM

Hi All,

I have wildcard dns setup. I am looking to standardise the domain the users see. Therefore, no matter what they type, the will see the formal domain name. I have tried loads of different rules that I have found on this forum and can't get it to work. Here is what I am trying to achieve.

www.domain.com --> DO NOTHING
www.domain.com/sub/ --> DO NOTHING
www.domain.com/sub/test.aspx?test=123 -- DO NOTHING

somethingelse.domain.com --> www.domain.com
somethingelse.domain.com/subfolder/ --> www.domain.com/subfolder/
somethingelse.domain.com/subfolder/test.aspx?test=123 --> www.domain.com/subfolder/test.aspx?test=123

Regards,
CFe 

Jun 22, 2009 at 11:20 AM

 

Bump


 

Coordinator
Jun 25, 2009 at 5:30 PM
Edited Jun 29, 2009 at 3:37 PM

How about....

  RewriteCond   %{SERVER_NAME}     (?!www)(.+)\.domain\.com   [I]
  RedirectRule  ^/(.*)$            http://www.domain.com/$1  [R=301]

This says, for any request that has a server_name not equal to www.domain.com, redirect to www.domain.com, with the full URI.

Jun 25, 2009 at 6:43 PM
Thanks. I'll give it a go.

2009/6/25 Cheeso <notifications@codeplex.com>

From: Cheeso

How about....

  RewriteCond   ${SERVER_NAME}     (?!www)(.+)\.domain\.com   [I]
  RedirectRule  ^/(.*)$            http://www.domain.com/$1  [R=301]

This says, for any request that has a server_name not equal to www.domain.com, redirect to www.domain.com, with the full URI.

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Jun 26, 2009 at 6:24 AM

Hi Cheeso,

There is no change. The domain name in the URL hasn't altered. The relevant piece of the log is:-

 

Fri Jun 26 07:17:35 -  2000 - EvalCondition: checking '${SERVER_NAME}' against pattern '(?!www)(.+)\.domain\.co\.uk'
Fri Jun 26 07:17:35 -  2000 - EvalCondition: match result: -1 (No match)
Fri Jun 26 07:17:35 -  2000 - EvaluateCondition: Child is NULL
Fri Jun 26 07:17:35 -  2000 - EvalCondition: returning FALSE
Fri Jun 26 07:17:35 -  2000 - EvalConditionList: rule 1, FALSE, Rule does not apply

Regards
CFe

Coordinator
Jun 26, 2009 at 7:40 PM

You can swap SERVER_NAME for HTTP_HOST.

 

Jun 26, 2009 at 8:48 PM
Same result. The url doesn't change. My other rules all work fine.

On 26 Jun 2009, at 20:41, Cheeso <notifications@codeplex.com> wrote:

From: Cheeso

You can swap SERVER_NAME for HTTP_HOST.

Coordinator
Jun 26, 2009 at 9:10 PM

can you turn logging to level 4 and let me see the log? (for one request)

Jun 29, 2009 at 5:47 AM
Hi Cheeso,

Thanks for your help on this.Here you go.


--------------------------------------------
Mon Jun 29 06:41:30 - 13792 - ReadConfig: setting LogLevel to 4
Mon Jun 29 06:41:30 - 13792 - ReadConfig: line 5: RewriteCond ${HTTP_HOST} (?!www)(.+)\.domain\.co\.uk 
Mon Jun 29 06:41:30 - 13792 - ParseCondModifierFlags: '[I]'
Mon Jun 29 06:41:30 - 13792 - ReadConfig: line 6: RedirectRule (rule 1) '^/(.*)$' 'http://www.domain.co.uk/$1' [R=301]
Mon Jun 29 06:41:30 - 13792 - ParseRuleModifierFlags: '[R=301]'
Mon Jun 29 06:41:30 - 13792 - ReadConfig: line 9: RedirectRule (rule 2) '^/([^.?]+[^.?/])$' '/$1/' [I,R=301]
Mon Jun 29 06:41:30 - 13792 - ParseRuleModifierFlags: '[I,R=301]'
Mon Jun 29 06:41:30 - 13792 - ReadConfig: WARNING: Redirecting to a target that does not include an http(s):// scheme.
Mon Jun 29 06:41:30 - 13792 - ReadConfig: line 12: RewriteRule (rule 3) '^/Messages/(.*)/' '/Messages.aspx?id=$1' [I]
Mon Jun 29 06:41:30 - 13792 - ParseRuleModifierFlags: '[I]'
Mon Jun 29 06:41:30 - 13792 - ReadConfig: line 14: RewriteRule (rule 4) '^/Search/(.*)/$' '/Search/Default.aspx?q=$1' [I]
Mon Jun 29 06:41:30 - 13792 - ParseRuleModifierFlags: '[I]'
Mon Jun 29 06:41:30 - 13792 - ReadConfig: line 15: RewriteRule (rule 5) '^/TM/$' '/Search/Default.aspx?view=tm' [I]
Mon Jun 29 06:41:30 - 13792 - ParseRuleModifierFlags: '[I]'
Mon Jun 29 06:41:30 - 13792 - ReadConfig: line 16: RewriteRule (rule 6) '^/TM/(.*)/$' '/Search/Default.aspx?view=tm&q=$1' [I]
Mon Jun 29 06:41:30 - 13792 - ParseRuleModifierFlags: '[I]'
Mon Jun 29 06:41:30 - 13792 - ReadConfig: line 18: RewriteRule (rule 7) '^/LogOut/Special/$' '/LogOut/Default.aspx?special=1' [I]
Mon Jun 29 06:41:30 - 13792 - ParseRuleModifierFlags: '[I]'
Mon Jun 29 06:41:30 - 13792 - ReadConfig: line 19: RewriteRule (rule 8) '^/LogOut/SignedOut/Special/$' '/LogOut/SignedOut/Default.aspx?special=1' [I]
Mon Jun 29 06:41:30 - 13792 - ParseRuleModifierFlags: '[I]'
Mon Jun 29 06:41:30 - 13792 - ReadConfig: Done reading, found 8 rules (0 errors, 1 warnings) on 20 lines

--------------------------------------------
Mon Jun 29 06:41:30 - 13792 - Initialize: Ionic ISAPI Rewriting Filter (IIRF) v1.2.15 final R3
Mon Jun 29 06:41:30 - 13792 - Initialize: config file 'E:\Itass\IonicIsapiRewriter\IsapiRewrite4.ini'
Mon Jun 29 06:41:30 - 13792 - Initialize: File watcher thread created.
Mon Jun 29 06:41:30 - 13792 - GetFilterVersion
Mon Jun 29 06:41:30 - 6548 - FileChangeWatcher(): Enter
Mon Jun 29 06:41:30 - 6548 - FileChangeWatcher: Await()...
Mon Jun 29 06:41:30 - 13792 - HttpFilterProc: SF_NOTIFY_URL_MAP
Mon Jun 29 06:41:30 - 13792 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Mon Jun 29 06:41:30 - 13792 - DoRewrites
Mon Jun 29 06:41:30 - 13792 - GetHeader_AutoFree: 2 bytes, result '/'
Mon Jun 29 06:41:30 - 13792 - GetHeader_AutoFree: 4 bytes, result 'GET'
Mon Jun 29 06:41:30 - 13792 - DoRewrites: New Url: '/'
Mon Jun 29 06:41:30 - 13792 - EvaluateRules: depth=0
Mon Jun 29 06:41:30 - 13792 - EvaluateRules: Rule 1 : 2 matches
Mon Jun 29 06:41:30 - 13792 - ReplaceServerVariables: InputString='${HTTP_HOST}' out='${HTTP_HOST}'
Mon Jun 29 06:41:30 - 13792 - EvalCondition: ts1 '${HTTP_HOST}'
Mon Jun 29 06:41:30 - 13792 - GenerateReplacementString: src='/','(null)' ReplacePattern='${HTTP_HOST}' vec=[[ [ 0, 1, 1, 1] [] ] counts=2,0
Mon Jun 29 06:41:30 - 13792 - ApplyCaseConversion: before '${HTTP_HOST}'
Mon Jun 29 06:41:30 - 13792 - ApplyCaseConversion: after '${HTTP_HOST}'
Mon Jun 29 06:41:30 - 13792 - GenerateReplacementString: result '${HTTP_HOST}'
Mon Jun 29 06:41:30 - 13792 - EvalCondition: checking '${HTTP_HOST}' against pattern '(?!www)(.+)\.domain\.co\.uk'
Mon Jun 29 06:41:30 - 13792 - EvalCondition: match result: -1 (No match)
Mon Jun 29 06:41:30 - 13792 - EvalCondition: returning FALSE
Mon Jun 29 06:41:30 - 13792 - EvalConditionList: rule 1, FALSE, Rule does not apply
Mon Jun 29 06:41:30 - 13792 - EvaluateRules: Rule 2 : -1 (No match)
Mon Jun 29 06:41:30 - 13792 - EvaluateRules: Rule 3 : -1 (No match)
Mon Jun 29 06:41:30 - 13792 - EvaluateRules: Rule 4 : -1 (No match)
Mon Jun 29 06:41:30 - 13792 - EvaluateRules: Rule 5 : -1 (No match)
Mon Jun 29 06:41:30 - 13792 - EvaluateRules: Rule 6 : -1 (No match)
Mon Jun 29 06:41:30 - 13792 - EvaluateRules: Rule 7 : -1 (No match)
Mon Jun 29 06:41:30 - 13792 - EvaluateRules: Rule 8 : -1 (No match)
Mon Jun 29 06:41:30 - 13792 - EvaluateRules: returning 0
Mon Jun 29 06:41:30 - 13792 - DoRewrites: No Rewrite
Mon Jun 29 06:41:30 - 13792 - HttpFilterProc: SF_NOTIFY_URL_MAP
Mon Jun 29 06:41:30 - 13792 - HttpFilterProc: SF_NOTIFY_URL_MAP
Mon Jun 29 06:41:31 - 11844 - HttpFilterProc: SF_NOTIFY_URL_MAP
Mon Jun 29 06:41:31 - 13792 - HttpFilterProc: SF_NOTIFY_URL_MAP
Mon Jun 29 06:41:31 - 13792 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Mon Jun 29 06:41:31 - 13792 - DoRewrites
Mon Jun 29 06:41:31 - 13792 - GetHeader_AutoFree: 26 bytes, result '/Elements/Stylesheet.aspx'
Mon Jun 29 06:41:31 - 13792 - GetHeader_AutoFree: 4 bytes, result 'GET'
Mon Jun 29 06:41:31 - 13792 - DoRewrites: New Url: '/Elements/Stylesheet.aspx'
Mon Jun 29 06:41:31 - 13792 - EvaluateRules: depth=0
Mon Jun 29 06:41:31 - 13792 - EvaluateRules: Rule 1 : 2 matches
Mon Jun 29 06:41:31 - 13792 - ReplaceServerVariables: InputString='${HTTP_HOST}' out='${HTTP_HOST}'
Mon Jun 29 06:41:31 - 13792 - EvalCondition: ts1 '${HTTP_HOST}'
Mon Jun 29 06:41:31 - 13792 - GenerateReplacementString: src='/Elements/Stylesheet.aspx','(null)' ReplacePattern='${HTTP_HOST}' vec=[[ [ 0, 25, 1, 25] [] ] counts=2,0
Mon Jun 29 06:41:31 - 13792 - ApplyCaseConversion: before '${HTTP_HOST}'
Mon Jun 29 06:41:31 - 13792 - ApplyCaseConversion: after '${HTTP_HOST}'
Mon Jun 29 06:41:31 - 13792 - GenerateReplacementString: result '${HTTP_HOST}'
Mon Jun 29 06:41:31 - 13792 - EvalCondition: checking '${HTTP_HOST}' against pattern '(?!www)(.+)\.domain\.co\.uk'
Mon Jun 29 06:41:31 - 13792 - EvalCondition: match result: -1 (No match)
Mon Jun 29 06:41:31 - 13792 - EvalCondition: returning FALSE
Mon Jun 29 06:41:31 - 13792 - EvalConditionList: rule 1, FALSE, Rule does not apply
Mon Jun 29 06:41:31 - 13792 - EvaluateRules: Rule 2 : -1 (No match)
Mon Jun 29 06:41:31 - 13792 - EvaluateRules: Rule 3 : -1 (No match)
Mon Jun 29 06:41:31 - 13792 - EvaluateRules: Rule 4 : -1 (No match)
Mon Jun 29 06:41:31 - 13792 - EvaluateRules: Rule 5 : -1 (No match)
Mon Jun 29 06:41:31 - 13792 - EvaluateRules: Rule 6 : -1 (No match)
Mon Jun 29 06:41:31 - 13792 - EvaluateRules: Rule 7 : -1 (No match)
Mon Jun 29 06:41:31 - 13792 - EvaluateRules: Rule 8 : -1 (No match)
Mon Jun 29 06:41:31 - 13792 - EvaluateRules: returning 0
Mon Jun 29 06:41:31 - 13792 - DoRewrites: No Rewrite
Mon Jun 29 06:41:31 - 13792 - HttpFilterProc: SF_NOTIFY_URL_MAP
Mon Jun 29 06:41:31 - 11844 - HttpFilterProc: SF_NOTIFY_URL_MAP

Regards,
CFe


2009/6/26 Cheeso <notifications@codeplex.com>

From: Cheeso

can you turn logging to level 4 and let me see the log? (for one request)

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Coordinator
Jun 29, 2009 at 9:11 AM

OK thanks.

Looking at the log I can see that the HTTP_HOST server variable is not being set.  Can you do the same thing, send me the log, using the RewriteCond that uses SERVER_NAME ?

 

Jun 29, 2009 at 11:32 AM

Here you go:

Mon Jun 29 12:27:06 - 13100 - HttpFilterProc: SF_NOTIFY_URL_MAP
Mon Jun 29 12:27:06 - 13100 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Mon Jun 29 12:27:06 - 13100 - DoRewrites
Mon Jun 29 12:27:06 - 13100 - GetHeader_AutoFree: 2 bytes, result '/'
Mon Jun 29 12:27:06 - 13100 - GetHeader_AutoFree: 4 bytes, result 'GET'
Mon Jun 29 12:27:06 - 13100 - DoRewrites: New Url: '/'
Mon Jun 29 12:27:06 - 13100 - EvaluateRules: depth=0
Mon Jun 29 12:27:06 - 13100 - EvaluateRules: Rule 1 : 2 matches
Mon Jun 29 12:27:06 - 13100 - ReplaceServerVariables: InputString='${SERVER_NAME}' out='${SERVER_NAME}'
Mon Jun 29 12:27:06 - 13100 - EvalCondition: ts1 '${SERVER_NAME}'
Mon Jun 29 12:27:06 - 13100 - GenerateReplacementString: src='/','(null)' ReplacePattern='${SERVER_NAME}' vec=[[ [ 0, 1, 1, 1] [] ] counts=2,0
Mon Jun 29 12:27:06 - 13100 - ApplyCaseConversion: before '${SERVER_NAME}'
Mon Jun 29 12:27:06 - 13100 - ApplyCaseConversion: after '${SERVER_NAME}'
Mon Jun 29 12:27:06 - 13100 - GenerateReplacementString: result '${SERVER_NAME}'
Mon Jun 29 12:27:06 - 13100 - EvalCondition: checking '${SERVER_NAME}' against pattern '(?!www)(.+)\.domain\.co\.uk'
Mon Jun 29 12:27:06 - 13100 - EvalCondition: match result: -1 (No match)
Mon Jun 29 12:27:06 - 13100 - EvalCondition: returning FALSE
Mon Jun 29 12:27:06 - 13100 - EvalConditionList: rule 1, FALSE, Rule does not apply
Mon Jun 29 12:27:06 - 13100 - EvaluateRules: Rule 2 : -1 (No match)
Mon Jun 29 12:27:06 - 13100 - EvaluateRules: Rule 3 : -1 (No match)
Mon Jun 29 12:27:06 - 13100 - EvaluateRules: Rule 4 : -1 (No match)
Mon Jun 29 12:27:06 - 13100 - EvaluateRules: Rule 5 : -1 (No match)
Mon Jun 29 12:27:06 - 13100 - EvaluateRules: Rule 6 : -1 (No match)
Mon Jun 29 12:27:06 - 13100 - EvaluateRules: Rule 7 : -1 (No match)
Mon Jun 29 12:27:06 - 13100 - EvaluateRules: Rule 8 : -1 (No match)
Mon Jun 29 12:27:06 - 13100 - EvaluateRules: returning 0
Mon Jun 29 12:27:06 - 13100 - DoRewrites: No Rewrite

Coordinator
Jun 29, 2009 at 3:37 PM

Excuse me, I'm truly sorry, I've been using $ when what I want to suggest is %

So,  please try %{SERVER_NAME} or %{HTTP_HOST}

.

 

Jun 29, 2009 at 6:42 PM
Thanks Cheeso,

The redirect is happening now, however, it's stuck in an endless loop. I'm thinking there is something wrong with the pattern (?!www)(.+)\.domain\.co\.uk

Is this correct to match anything other than www.domain.co.uk?

Regards,
CFe

2009/6/29 Cheeso <notifications@codeplex.com>

From: Cheeso

Excuse me, I'm truly sorry, I've been using $ when what I want to suggest is %

So,  please try %{SERVER_NAME} or %{HTTP_HOST}

.

 

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Coordinator
Jun 29, 2009 at 7:10 PM

Bracket that regex with ^ and $ (beginning of line, end of line), so that you have ^(?!www)(.+)\.domain\.co\.uk$

 

Jun 29, 2009 at 7:28 PM
You are BRILLIANT!!!!

Thank you soooo much. Cheeso ... you are a legend.

2009/6/29 Cheeso <notifications@codeplex.com>

From: Cheeso

Bracket that regex with ^ and $ (beginning of line, end of line), so that you have ^(?!www)(.+)\.domain\.co\.uk$

 

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com