UrlRewriter.net redirect non-www to www

1.5k Views Asked by At

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" />
4

There are 4 best solutions below

0
On

try this

<redirect url="http://example\.com(.+)" to="http://www.example.com$1" />
0
On

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 :)

0
On

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>
0
On

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!