2

How do I create an UrlRewriter.net redirect rule to redirect non-www pages to www?

I have found htaccess and ISAPI examples, but cannot find the proper regex rule for UrlRewriter. For example, this doesn't work:

<redirect url="http://example.com(.+)" to="http://www.example.com$1" />
Lance Roberts
  • 22,383
  • 32
  • 112
  • 130
regexnewb
  • 23
  • 4

4 Answers4

1

If you are not currently using a rewrite module and this is all new then I would recommend using the IIS rewrite module version2

With this you can create new rules based on templates and Canonical rules are there to select so you don't need to write your own :)

Andrew
  • 9,967
  • 10
  • 64
  • 103
0

The following worked for me in Umbraco 4.9.1 - In the UrlRewriting.config, use this:

<add name="forcewww" virtualUrl="http\://(?!www\.)" redirectMode="Temporary" destinationUrl="http://www." ignoreCase="true" redirect="Domain" />

This also carries through any querystring parameters that might have been in the original request.  Depending on your needs, you might prefer to set the redirectMode to Permanent.  Happy coding!

0

I was looking here for a solution here, but none of the suggestions work with the version of Intelligencia.UrlRewriter.dll that I'm using. I've tested and I'm using the following:

    <if header="HTTP_HOST" match="example.com">
        <redirect url="(.*)" to="http://www.example.com$1" />
    </if>
Myster
  • 17,704
  • 13
  • 64
  • 93
0

try this

<redirect url="http://example\.com(.+)" to="http://www.example.com$1" />
zer0w1dthspace
  • 1,042
  • 2
  • 17
  • 34