开发者

UrlRewriter.net redirect non-www to www

开发者 https://www.devze.com 2023-02-24 02:21 出处:网络
How do I create an UrlRewriter.net redirect rule to redirect non-www pages to www? I have found htaccess and ISAPI examples, b开发者_如何学Cut cannot find the proper regex rule for UrlRewriter. For e

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

I have found htaccess and ISAPI examples, b开发者_如何学Cut 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" />


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


try this

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


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!


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号