Need Example for Simple Redirect to www

Jun 7, 2008 at 1:05 PM
I would like to use nUrlRewriter to do the following with a DNN site and need some examples.

I have two domain names (MyDomain.com and MyDomain.org) that I want to point to the same site.  I setup DNS and IIS so that a visitor can navigate to the site using any of the following four URLs:
http://www.MyDomain.org
http://MyDomain.org
http://www.MyDomain.com
http://MyDomain.com
I want the visitor to be permanently redirected to http://www.MyDomain.org

Could someone with some experience please provide me with an example.

Thanks very much in advance.

Coordinator
Jun 8, 2008 at 2:52 AM
Edited Jun 8, 2008 at 5:13 PM
So....please clarify.   You want to permanently redirect http://www.MyDomain.org, http://MyDomain.org, http://www.MyDomain.com and http://MyDomain.com to http://www.MyDomain.org ?

If the above understanding is correct ....then the following should work...

<add name="RuleCOM"
        action="redirect"
        ignoreCase="true"
        redirectType="permanent"
        transformType="RegExReplace"
        fromScope="absolute"
        from="^http(?&lt;SSL&gt;[s]?)://(www.)?mydomain.com/(?&lt;WebPage&gt;(.*))$"
        to="http${SSL}://www.mydomain.org/${WebPage}" />

<

 

add name="RuleORG"
        action="redirect"
        ignoreCase="true"
        redirectType="permanent"
        transformType="RegExReplace"
        fromScope="absolute"
        from="^http(?&lt;SSL&gt;[s]?)://(www.)?mydomain.org/(?&lt;WebPage&gt;(.*))$"
        to="http${SSL}://www.mydomain.org/${WebPage}" />


You can also try combining the above two regular expression rules into this single rule.... I have not tested this.....however it should take care of all cases...

<add name="RuleOnly"
        action="redirect"
        ignoreCase="true"
        redirectType="permanent"
        transformType="RegExReplace"
        fromScope="absolute"
        from="^http(?&lt;SSL&gt;[s]?)://(www.)?mydomain.(org|com)/(?&lt;WebPage&gt;(.*))$"
        to="http${SSL}://www.mydomain.org/${WebPage}" />

Good Luck.... 

Jun 28, 2008 at 3:36 PM
Edited Jun 28, 2008 at 4:10 PM

Sorry for the delay in responding.  I wanted to experiment with this a bit first.

The first method, using two Rules, caused the browser to endlessly loop until I modified the "From" Attribute of the "RuleORG" Rule removing the string "(www.)?".  Then it worked GREAT!

Example:

add name="RuleORG"
        action="redirect"
        ignoreCase="true"
        redirectType="permanent"
        transformType="RegExReplace"
        fromScope="absolute"
        from="^http(?&lt;SSL&gt;[s]?)://mydomain.org/(?&lt;WebPage&gt;(.*))$"
        to="http${SSL}://www.mydomain.org/${WebPage}" />

The second method, with one rule, failed in the same way but the same modification won't fix it completely so you would still need two rules.

Doing it in one rule would be nice, but not at all necessary.

Thank you again, VERY MUCH, for this wonderful contribution.