Rewrite Rule | Redirect Change | Help

Topics: Developer Forum, Project Management Forum, User Forum
Sep 5, 2008 at 6:28 PM
I have the following rule which works but i need to tweak a little bit so it also redirects request that have WWW on it.

# This rule redirects if its missing the WWW

RewriteCond %{HTTP_HOST} ^(?!www\.)((domain1|domain2)\.com)$
RewriteRule ^/(.*)$        https://www.%1/$1    [R]

# This rule redirects if it has "WWW" on the request
# This one below is not working, not sure if i need to just write one rule that will take care of both conditions.

RewriteCond %{HTTP_HOST} ^(www\.(domain1|domain2)\.com)$
RewriteRule ^/(.*)$            https://%1.%1/$2   [R]

------------------------------------------------------------------
Basically i need al incomming traffic to this domains to redirect to a secure URL with https.

If its missing the WWW, it will add it and also redirect to the HTTPS

If it has WWW in front of domain i also want it to redirect to https.

Do i need two conditions and two rewrite rules? i know i missing something...
Sep 5, 2008 at 11:06 PM
Edited Sep 5, 2008 at 11:07 PM
the rule above is doing two things. adding the www if it doesnt have it and also redirecting to https.

i need to also add to redirect to https if it has www.

i try adding as above but apparently doesn't work so i comment it out.
Sep 6, 2008 at 8:13 PM
NO help here?
Coordinator
Sep 10, 2008 at 12:30 AM

I Can try to help you.

Can you post your logfile?  to keep it simple, ideally you have only a single rule in your ini file - the one that is not working as expected. Then, I'd like to see the complete log for a single request. In other words, send a GET to http://www.domain1.com and then show me the logfile that results after IIRF processes that URL.

 

Sep 10, 2008 at 9:30 PM
# This rule redirects if its missing the www + mach domain
    The two rules should redirect to https

RewriteCond %{HTTP_HOST} ^(?!www\.)((domain1|domain2)\.dev1)$
RewriteRule ^/(.*)$        https://www.%1/$1    [R]

# This rule redirects if it has WWW on the request + mach domain
    The two rules should redirect to https

RewriteCond %{HTTP_HOST} ^www\.((domain1|domain2)\.dev1)$
RewriteRule ^/(.*)$         https://%1/$1    [R]

LOG
################################################

--------------------------------------------
Wed Sep 10 17:22:53 2008 - LogFile re-opened.
Wed Sep 10 17:22:53 2008 - AwaitIniChangeAndReinit: Detected change in the  ini file 'C:\WINDOWS\system32\isapibeta\IsapiRewrite4.ini'
Wed Sep 10 17:22:53 2008 - AwaitIniChangeAndReinit: Ionic ISAPI Rewriting Filter (IIRF) v1.2.14 final R3
Wed Sep 10 17:22:53 2008 - ReadConfig
Wed Sep 10 17:22:53 2008 - LogFile re-opened.
Wed Sep 10 17:22:53 2008 - ReadConfig: new log file name: 'c:\temp\iirfLog3.out.7536.log'
Wed Sep 10 17:22:53 2008 - ReadConfig: setting LogLevel to 3
Wed Sep 10 17:22:53 2008 - ReadConfig: line   8: RewriteCond %{HTTP_HOST}                                   ^(?!www\.)((domain1)\.dev1)$             
Wed Sep 10 17:22:53 2008 - ReadConfig: line   9: RewriteRule   1 ^/(.*)$                                        https://www.%1/$1                               [R]
Wed Sep 10 17:22:53 2008 - ParseRuleModifierFlags: '[R]'
Wed Sep 10 17:22:53 2008 - ReadConfig: line  15: RewriteCond %{HTTP_HOST}                                   ^www\.((domain1)\.dev1)$                 
Wed Sep 10 17:22:53 2008 - ReadConfig: line  16: RewriteRule   2 ^/(.*)$                                        https://%1/$1                                   [R]
Wed Sep 10 17:22:53 2008 - ParseRuleModifierFlags: '[R]'
Wed Sep 10 17:22:53 2008 - ReadConfig: Done reading, found 2 rules (0 failed) on 17 lines

--------------------------------------------
Wed Sep 10 17:22:53 2008 - LogFile re-opened.
Wed Sep 10 17:23:04 2008 - DllMain THREAD_DETACH, threadId= 5492
Wed Sep 10 17:23:04 2008 - DllMain THREAD_DETACH, threadId= 7616
Wed Sep 10 17:23:04 2008 - DllMain THREAD_DETACH, threadId= 7676
Wed Sep 10 17:23:19 2008 - DllMain THREAD_DETACH, threadId= 7724
Wed Sep 10 17:23:30 2008 - AwaitIniChangeAndReinit: Detected change in the  ini file 'C:\WINDOWS\system32\isapibeta\IsapiRewrite4.ini'
Wed Sep 10 17:23:30 2008 - AwaitIniChangeAndReinit: Ionic ISAPI Rewriting Filter (IIRF) v1.2.14 final R3
Wed Sep 10 17:23:30 2008 - ReadConfig
Wed Sep 10 17:23:30 2008 - LogFile re-opened.
Wed Sep 10 17:23:30 2008 - ReadConfig: new log file name: 'c:\temp\iirfLog3.out.7536.log'
Wed Sep 10 17:23:30 2008 - ReadConfig: setting LogLevel to 3
Wed Sep 10 17:23:30 2008 - ReadConfig: line   8: RewriteCond %{HTTP_HOST}                                   ^(?!www\.)((domain1|domain2)\.dev1)$     
Wed Sep 10 17:23:30 2008 - ReadConfig: line   9: RewriteRule   1 ^/(.*)$                                        https://www.%1/$1                               [R]
Wed Sep 10 17:23:30 2008 - ParseRuleModifierFlags: '[R]'
Wed Sep 10 17:23:30 2008 - ReadConfig: line  15: RewriteCond %{HTTP_HOST}                                   ^www\.((domain1|domain2)\.dev1)$         
Wed Sep 10 17:23:30 2008 - ReadConfig: line  16: RewriteRule   2 ^/(.*)$                                        https://%1/$1                                   [R]
Wed Sep 10 17:23:30 2008 - ParseRuleModifierFlags: '[R]'
Wed Sep 10 17:23:30 2008 - ReadConfig: Done reading, found 2 rules (0 failed) on 17 lines

--------------------------------------------
Wed Sep 10 17:23:30 2008 - LogFile re-opened.
Wed Sep 10 17:23:30 2008 - AwaitIniChangeAndReinit: Detected change in the  ini file 'C:\WINDOWS\system32\isapibeta\IsapiRewrite4.ini'
Wed Sep 10 17:23:30 2008 - AwaitIniChangeAndReinit: Ionic ISAPI Rewriting Filter (IIRF) v1.2.14 final R3
Wed Sep 10 17:23:30 2008 - ReadConfig
Wed Sep 10 17:23:30 2008 - LogFile re-opened.
Wed Sep 10 17:23:30 2008 - ReadConfig: new log file name: 'c:\temp\iirfLog3.out.7536.log'
Wed Sep 10 17:23:30 2008 - ReadConfig: setting LogLevel to 3
Wed Sep 10 17:23:30 2008 - ReadConfig: line   8: RewriteCond %{HTTP_HOST}                                   ^(?!www\.)((domain1|domain2)\.dev1)$     
Wed Sep 10 17:23:30 2008 - ReadConfig: line   9: RewriteRule   1 ^/(.*)$                                        https://www.%1/$1                               [R]
Wed Sep 10 17:23:30 2008 - ParseRuleModifierFlags: '[R]'
Wed Sep 10 17:23:30 2008 - ReadConfig: line  15: RewriteCond %{HTTP_HOST}                                   ^www\.((domain1|domain2)\.dev1)$         
Wed Sep 10 17:23:30 2008 - ReadConfig: line  16: RewriteRule   2 ^/(.*)$                                        https://%1/$1                                   [R]
Wed Sep 10 17:23:30 2008 - ParseRuleModifierFlags: '[R]'
Wed Sep 10 17:23:30 2008 - ReadConfig: Done reading, found 2 rules (0 failed) on 17 lines

--------------------------------------------
Wed Sep 10 17:23:30 2008 - LogFile re-opened.
Wed Sep 10 17:23:43 2008 - HttpFilterProc: SF_NOTIFY_URL_MAP
Wed Sep 10 17:23:43 2008 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Wed Sep 10 17:23:43 2008 - DoRewrites
Wed Sep 10 17:23:43 2008 - GetServerVariable_AutoFree - no joy (GetLastError()=1413)
Wed Sep 10 17:23:43 2008 - DoRewrites: New Url: '/'
Wed Sep 10 17:23:43 2008 - ApplyRules: depth=0
Wed Sep 10 17:23:43 2008 - ApplyRules: Rule 1 : 2 matches
Wed Sep 10 17:23:43 2008 - EvalCondition: ts1 'www.domain1.dev1'
Wed Sep 10 17:23:43 2008 - ApplyCaseConversion: after  'www.domain1.dev1'
Wed Sep 10 17:23:43 2008 - EvalCondition: checking 'www.domain1.dev1' against pattern '^(?!www\.)((domain1|domain2)\.dev1)$'
Wed Sep 10 17:23:43 2008 - EvalCondition: match result: -1 (No match)
Wed Sep 10 17:23:43 2008 - EvalConditionList: FALSE, Rule does not apply
Wed Sep 10 17:23:43 2008 - ApplyRules: Rule 2 : 2 matches
Wed Sep 10 17:23:43 2008 - EvalCondition: ts1 'www.domain1.dev1'
Wed Sep 10 17:23:43 2008 - ApplyCaseConversion: after  'www.domain1.dev1'
Wed Sep 10 17:23:43 2008 - EvalCondition: checking 'www.domain1.dev1' against pattern '^www\.((domain1|domain2)\.dev1)$'
Wed Sep 10 17:23:43 2008 - EvalCondition: match result: 3 (match)
Wed Sep 10 17:23:43 2008 - EvalConditionList: TRUE, Rule will apply
Wed Sep 10 17:23:43 2008 - ApplyCaseConversion: after  'https://domain1.dev1/'
Wed Sep 10 17:23:43 2008 - ApplyRules: Result (length 21): https://domain1.dev1/
Wed Sep 10 17:23:43 2008 - ApplyRules: returning 302
Wed Sep 10 17:23:43 2008 - DoRewrites: Redirect (code=302) Url to: 'https://domain1.dev1/'
Wed Sep 10 17:23:43 2008 - DoRewrites: Finished
Wed Sep 10 17:24:00 2008 - HttpFilterProc: SF_NOTIFY_URL_MAP
Wed Sep 10 17:24:00 2008 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Wed Sep 10 17:24:00 2008 - DoRewrites
Wed Sep 10 17:24:00 2008 - GetServerVariable_AutoFree - no joy (GetLastError()=1413)
Wed Sep 10 17:24:00 2008 - DoRewrites: New Url: '/'
Wed Sep 10 17:24:00 2008 - ApplyRules: depth=0
Wed Sep 10 17:24:00 2008 - ApplyRules: Rule 1 : 2 matches
Wed Sep 10 17:24:00 2008 - EvalCondition: ts1 'domain1.dev1'
Wed Sep 10 17:24:00 2008 - ApplyCaseConversion: after  'domain1.dev1'
Wed Sep 10 17:24:00 2008 - EvalCondition: checking 'domain1.dev1' against pattern '^(?!www\.)((domain1|domain2)\.dev1)$'
Wed Sep 10 17:24:00 2008 - EvalCondition: match result: 3 (match)
Wed Sep 10 17:24:00 2008 - EvalConditionList: TRUE, Rule will apply
Wed Sep 10 17:24:00 2008 - ApplyCaseConversion: after  'https://www.domain1.dev1/'
Wed Sep 10 17:24:00 2008 - ApplyRules: Result (length 25): https://www.domain1.dev1/
Wed Sep 10 17:24:00 2008 - ApplyRules: returning 302
Wed Sep 10 17:24:00 2008 - DoRewrites: Redirect (code=302) Url to: 'https://www.domain1.dev1/'
Wed Sep 10 17:24:00 2008 - DoRewrites: Finished
Wed Sep 10 17:24:19 2008 - HttpFilterProc: SF_NOTIFY_URL_MAP
Wed Sep 10 17:24:19 2008 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Wed Sep 10 17:24:19 2008 - DoRewrites
Wed Sep 10 17:24:19 2008 - GetServerVariable_AutoFree - no joy (GetLastError()=1413)
Wed Sep 10 17:24:19 2008 - DoRewrites: New Url: '/'
Wed Sep 10 17:24:19 2008 - ApplyRules: depth=0
Wed Sep 10 17:24:19 2008 - ApplyRules: Rule 1 : 2 matches
Wed Sep 10 17:24:19 2008 - EvalCondition: ts1 'www.domain1.dev1'
Wed Sep 10 17:24:19 2008 - ApplyCaseConversion: after  'www.domain1.dev1'
Wed Sep 10 17:24:19 2008 - EvalCondition: checking 'www.domain1.dev1' against pattern '^(?!www\.)((domain1|domain2)\.dev1)$'
Wed Sep 10 17:24:19 2008 - EvalCondition: match result: -1 (No match)
Wed Sep 10 17:24:19 2008 - EvalConditionList: FALSE, Rule does not apply
Wed Sep 10 17:24:19 2008 - ApplyRules: Rule 2 : 2 matches
Wed Sep 10 17:24:19 2008 - EvalCondition: ts1 'www.domain1.dev1'
Wed Sep 10 17:24:19 2008 - ApplyCaseConversion: after  'www.domain1.dev1'
Wed Sep 10 17:24:19 2008 - EvalCondition: checking 'www.domain1.dev1' against pattern '^www\.((domain1|domain2)\.dev1)$'
Wed Sep 10 17:24:19 2008 - EvalCondition: match result: 3 (match)
Wed Sep 10 17:24:19 2008 - EvalConditionList: TRUE, Rule will apply
Wed Sep 10 17:24:19 2008 - ApplyCaseConversion: after  'https://domain1.dev1/'
Wed Sep 10 17:24:19 2008 - ApplyRules: Result (length 21): https://domain1.dev1/
Wed Sep 10 17:24:19 2008 - ApplyRules: returning 302
Wed Sep 10 17:24:19 2008 - DoRewrites: Redirect (code=302) Url to: 'https://domain1.dev1/'
Wed Sep 10 17:24:19 2008 - DoRewrites: Finished
Wed Sep 10 17:24:24 2008 - DllMain THREAD_DETACH, threadId= 7720
Wed Sep 10 17:24:24 2008 - DllMain THREAD_DETACH, threadId= 7716
Wed Sep 10 17:24:24 2008 - DllMain THREAD_DETACH, threadId= 3512
Wed Sep 10 17:24:24 2008 - DllMain THREAD_DETACH, threadId= 7684
Wed Sep 10 17:24:24 2008 - DllMain THREAD_DETACH, threadId= 7580
Wed Sep 10 17:24:49 2008 - DllMain THREAD_DETACH, threadId= 6924
Wed Sep 10 17:24:51 2008 - HttpFilterProc: SF_NOTIFY_URL_MAP
Wed Sep 10 17:24:51 2008 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Wed Sep 10 17:24:51 2008 - DoRewrites
Wed Sep 10 17:24:51 2008 - GetServerVariable_AutoFree - no joy (GetLastError()=1413)
Wed Sep 10 17:24:51 2008 - DoRewrites: New Url: '/'
Wed Sep 10 17:24:51 2008 - ApplyRules: depth=0
Wed Sep 10 17:24:51 2008 - ApplyRules: Rule 1 : 2 matches
Wed Sep 10 17:24:51 2008 - EvalCondition: ts1 'domain1.dev1'
Wed Sep 10 17:24:51 2008 - ApplyCaseConversion: after  'domain1.dev1'
Wed Sep 10 17:24:51 2008 - EvalCondition: checking 'domain1.dev1' against pattern '^(?!www\.)((domain1|domain2)\.dev1)$'
Wed Sep 10 17:24:51 2008 - EvalCondition: match result: 3 (match)
Wed Sep 10 17:24:51 2008 - EvalConditionList: TRUE, Rule will apply
Wed Sep 10 17:24:51 2008 - ApplyCaseConversion: after  'https://www.domain1.dev1/'
Wed Sep 10 17:24:51 2008 - ApplyRules: Result (length 25): https://www.domain1.dev1/
Wed Sep 10 17:24:51 2008 - ApplyRules: returning 302
Wed Sep 10 17:24:51 2008 - DoRewrites: Redirect (code=302) Url to: 'https://www.domain1.dev1/'
Wed Sep 10 17:24:51 2008 - DoRewrites: Finished
Wed Sep 10 17:25:02 2008 - HttpFilterProc: SF_NOTIFY_URL_MAP
Wed Sep 10 17:25:02 2008 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Wed Sep 10 17:25:02 2008 - DoRewrites
Wed Sep 10 17:25:02 2008 - GetServerVariable_AutoFree - no joy (GetLastError()=1413)
Wed Sep 10 17:25:02 2008 - DoRewrites: New Url: '/'
Wed Sep 10 17:25:02 2008 - ApplyRules: depth=0
Wed Sep 10 17:25:02 2008 - ApplyRules: Rule 1 : 2 matches
Wed Sep 10 17:25:02 2008 - EvalCondition: ts1 'www.domain1.dev1'
Wed Sep 10 17:25:02 2008 - ApplyCaseConversion: after  'www.domain1.dev1'
Wed Sep 10 17:25:02 2008 - EvalCondition: checking 'www.domain1.dev1' against pattern '^(?!www\.)((domain1|domain2)\.dev1)$'
Wed Sep 10 17:25:02 2008 - EvalCondition: match result: -1 (No match)
Wed Sep 10 17:25:02 2008 - EvalConditionList: FALSE, Rule does not apply
Wed Sep 10 17:25:02 2008 - ApplyRules: Rule 2 : 2 matches
Wed Sep 10 17:25:02 2008 - EvalCondition: ts1 'www.domain1.dev1'
Wed Sep 10 17:25:02 2008 - ApplyCaseConversion: after  'www.domain1.dev1'
Wed Sep 10 17:25:02 2008 - EvalCondition: checking 'www.domain1.dev1' against pattern '^www\.((domain1|domain2)\.dev1)$'
Wed Sep 10 17:25:02 2008 - EvalCondition: match result: 3 (match)
Wed Sep 10 17:25:02 2008 - EvalConditionList: TRUE, Rule will apply
Wed Sep 10 17:25:02 2008 - ApplyCaseConversion: after  'https://domain1.dev1/'
Wed Sep 10 17:25:02 2008 - ApplyRules: Result (length 21): https://domain1.dev1/
Wed Sep 10 17:25:02 2008 - ApplyRules: returning 302
Wed Sep 10 17:25:02 2008 - DoRewrites: Redirect (code=302) Url to: 'https://domain1.dev1/'
Wed Sep 10 17:25:02 2008 - DoRewrites: Finished
Wed Sep 10 17:25:44 2008 - DllMain THREAD_DETACH, threadId= 7620
Wed Sep 10 17:25:49 2008 - DllMain THREAD_DETACH, threadId= 7824
Wed Sep 10 17:26:22 2008 - AwaitIniChangeAndReinit: Detected change in the  ini file 'C:\WINDOWS\system32\isapibeta\IsapiRewrite4.ini'
Wed Sep 10 17:26:22 2008 - AwaitIniChangeAndReinit: Ionic ISAPI Rewriting Filter (IIRF) v1.2.14 final R3
Wed Sep 10 17:26:22 2008 - ReadConfig
Wed Sep 10 17:26:22 2008 - LogFile re-opened.
Wed Sep 10 17:26:22 2008 - ReadConfig: new log file name: 'c:\temp\iirfLog3.out.7536.log'
Wed Sep 10 17:26:22 2008 - ReadConfig: setting LogLevel to 3
Wed Sep 10 17:26:22 2008 - ReadConfig: WARNING: line 7: Ignoring line: 'The'
Wed Sep 10 17:26:22 2008 - ReadConfig: line   9: RewriteCond %{HTTP_HOST}                                   ^(?!www\.)((domain1|domain2)\.dev1)$     
Wed Sep 10 17:26:22 2008 - ReadConfig: line  10: RewriteRule   1 ^/(.*)$                                        https://www.%1/$1                               [R]
Wed Sep 10 17:26:22 2008 - ParseRuleModifierFlags: '[R]'
Wed Sep 10 17:26:22 2008 - ReadConfig: WARNING: line 15: Ignoring line: 'The'
Wed Sep 10 17:26:22 2008 - ReadConfig: line  17: RewriteCond %{HTTP_HOST}                                   ^www\.((domain1|domain2)\.dev1)$         
Wed Sep 10 17:26:22 2008 - ReadConfig: line  18: RewriteRule   2 ^/(.*)$                                        https://%1/$1                                   [R]
Wed Sep 10 17:26:22 2008 - ParseRuleModifierFlags: '[R]'
Wed Sep 10 17:26:22 2008 - ReadConfig: Done reading, found 2 rules (0 failed) on 19 lines

--------------------------------------------
Wed Sep 10 17:26:22 2008 - LogFile re-opened.
Wed Sep 10 17:26:22 2008 - AwaitIniChangeAndReinit: Detected change in the  ini file 'C:\WINDOWS\system32\isapibeta\IsapiRewrite4.ini'
Wed Sep 10 17:26:22 2008 - AwaitIniChangeAndReinit: Ionic ISAPI Rewriting Filter (IIRF) v1.2.14 final R3
Wed Sep 10 17:26:22 2008 - ReadConfig
Wed Sep 10 17:26:22 2008 - LogFile re-opened.
Wed Sep 10 17:26:22 2008 - ReadConfig: new log file name: 'c:\temp\iirfLog3.out.7536.log'
Wed Sep 10 17:26:22 2008 - ReadConfig: setting LogLevel to 3
Wed Sep 10 17:26:22 2008 - ReadConfig: WARNING: line 7: Ignoring line: 'The'
Wed Sep 10 17:26:22 2008 - ReadConfig: line   9: RewriteCond %{HTTP_HOST}                                   ^(?!www\.)((domain1|domain2)\.dev1)$     
Wed Sep 10 17:26:22 2008 - ReadConfig: line  10: RewriteRule   1 ^/(.*)$                                        https://www.%1/$1                               [R]
Wed Sep 10 17:26:22 2008 - ParseRuleModifierFlags: '[R]'
Wed Sep 10 17:26:22 2008 - ReadConfig: WARNING: line 15: Ignoring line: 'The'
Wed Sep 10 17:26:22 2008 - ReadConfig: line  17: RewriteCond %{HTTP_HOST}                                   ^www\.((domain1|domain2)\.dev1)$         
Wed Sep 10 17:26:22 2008 - ReadConfig: line  18: RewriteRule   2 ^/(.*)$                                        https://%1/$1                                   [R]
Wed Sep 10 17:26:22 2008 - ParseRuleModifierFlags: '[R]'
Wed Sep 10 17:26:22 2008 - ReadConfig: Done reading, found 2 rules (0 failed) on 19 lines

--------------------------------------------
Wed Sep 10 17:26:22 2008 - LogFile re-opened.
Wed Sep 10 17:26:55 2008 - DllMain THREAD_DETACH, threadId= 7704
Wed Sep 10 17:27:04 2008 - DllMain THREAD_DETACH, threadId= 7916
Wed Sep 10 17:27:04 2008 - DllMain THREAD_DETACH, threadId= 7996
Wed Sep 10 17:27:12 2008 - DllMain THREAD_DETACH, threadId= 7752
Wed Sep 10 17:27:19 2008 - DllMain THREAD_DETACH, threadId= 8068
Wed Sep 10 17:28:18 2008 - DllMain THREAD_DETACH, threadId= 8140
Wed Sep 10 17:29:04 2008 - DllMain THREAD_DETACH, threadId= 6232
Wed Sep 10 17:29:19 2008 - DllMain THREAD_DETACH, threadId= 6012

Sep 10, 2008 at 9:32 PM
Im trying to do two things:

add WWW to the redirect if it's missing

change the port to https

I might be able to combine everything into one. dont know how too
Coordinator
Sep 11, 2008 at 8:05 PM

You've said "it isn't working."  What exactly isn't working?
What do you expect to see?  And what do you see actually happening?

I think from your description, you want the 2nd rule to be:

RewriteCond %{HTTP_HOST} ^(www\.(domain1|domain2)\.dev1)$
RewriteRule ^/(.*)$         https://%1/$1    [R]

The way you have it, %1 resolves to "domain1.dev1". The way I have it above, %1 resolves to "www.domain1.dev1".

I am not sure if this solves your problem or not, because so far all I understand is that "it isn't working".

ps: The lines you have in your ini file that read "The two rules should redirect to https" are comments and should be prefixed with #. You will avoid the warnings in the logfile if you do this. Otherwise they are harmless.

Sep 15, 2008 at 2:02 PM
RewriteCond %{HTTP_HOST} ^(www\.(domain1|domain2)\.dev1)$
RewriteRule ^/(.*)$         https://%1/$1    [R]

-------------------------------------
Redirect Loop
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

IE will never complete, it stays on loop.
-------------------------------------
Coordinator
Sep 15, 2008 at 5:20 PM
Ok.
well it seems like you may want to NOT redirect when the request is already https. 
You may want to add another RewriteCond to that rule, for example 

RewriteCond  SERVER_PORT  (?!443)
Sep 15, 2008 at 5:41 PM
Ill try this. Thanks
Sep 17, 2008 at 3:54 PM
Edited Sep 17, 2008 at 5:32 PM
Im still getting the loop problem with a simple url.
www.domain1.dev1

When this rule is run by itself:

RewriteCond %{HTTP_HOST} ^(www\.domain1\.dev1)$
RewriteCond  SERVER_PORT  (?!443)
RewriteRule ^/(.*)$         https://%1/$1    [R]


Running only this redirects to this: https://%1/

When both of this run together:


RewriteCond %{HTTP_HOST} ^(?!www\.)(domain1)\.dev1)$
RewriteRule ^/(.*)$        https://www.%1/$1    [R]

RewriteCond %{HTTP_HOST} ^(www\.domain1\.dev1)$
RewriteCond  SERVER_PORT  (?!443)
RewriteRule ^/(.*)$         https://%1/$1    [R]


Loops



Coordinator
Sep 17, 2008 at 4:32 PM
The RewriteCond on your first rule is broken - There is a missing paren.
I'll bet if you look in your logfile you will see a warning about it.

Otherwise, I don't see the loop in the IIRF logic.  Do you mean that you get a notice in firefox that the redirect is looping?

You have two rules.
The second rule says:  if the HTTP_HOST is www.domain1.dev1, and if the SERVER_PORT is not 443 (in other words, not using https), then redirect to https://www.domain1.dev1

Can you explain what you want to do with the first rule? In english?
I think what you want is... if the HTTP_HOST is domain1.dev1, then redirect to https://www.domain1.dev1  But the

The last thing - I'd advise you to look in your log file.
It is hard for me to diagnose the behavior of the server without the logfile.  I don't need to look at the logs, but you should.  You should look at them and read them and check for warnings on the rules and so on. 

Run one URL and then look at the log and see if you can find the loop.

Sep 17, 2008 at 5:46 PM
First Rule Explanation (In English):

The first rule checks if the domain is missing "www" in the url.

If TRUE then it will add it and redirect to "www.DOMAIN" also switching to https from http.
Sep 17, 2008 at 6:01 PM
The actual first rule:

RewriteCond %{HTTP_HOST} ^(?!www\.)((domain1|domain2|domain3)\.dev1)$
RewriteRule ^/(.*)$        https://www.%1/$1    [R]
Coordinator
Sep 17, 2008 at 6:34 PM
ah, ok,. makes sense.

the log files.  what do they tell you?
Sep 17, 2008 at 9:01 PM
This block is what actually end up working and stopped the endless loop which the index page was causing:
-----------------------------------------
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} ^(?!www\.)((domain1|domain2)\.dev1)$
RewriteRule ^/(.*)$        https://www.%1/$1    [R]

RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} ^(www\.(domain1|domain2)\.dev1)$
RewriteRule ^/(.*)$         https://%1/$1    [R]


-------------------------------------
The before suggested line : RewriteCond  SERVER_PORT  (?!443)

Did not work so i inverted by checking for port 80. So if it matched 80, then do it, if not, don't do nothing.

I want to thank Cheeso again for his excellent support and dedication to help me figure out this.

First conditions & rule accomplish two things.
  1. Adds "www" to a domain if it's missing.
  2. Redirects the new string (if www was added) to HTTPS.
Second  conditions & rule accomplish two things.
  1. Checks if it has "www" in the domain.
  2. Redirects same string HTTPS.
Any of the above two rules apply only if the user enters the site using server port 80 (non-https)

The second rule was really the only one that needed the extra port check, this because we are using code redirection also after the isapi did his job, but i added to both, just in case since i don't want to change anything on a already secure url.

Thanks Guys..!
Coordinator
Sep 18, 2008 at 3:26 AM
Super!  So glad you got it working.