Mono Support how to remove www and set 301 on urlrewriter 

Viewed 17272 time(s), 16 post(s), 1/21/2013 11:16:52 AM - by deska5
1/21/2013 11:16:52 AM
56 Reputation 7 Total posts

Hi All,

I would like to remove "www" prefix from my address. For example change www.mydomain.com to mydomain.com and set 301 redirect.
How can i do it in Monox? I found some .NET solutions but this is for standard url rewrite module, i need solution especially for MonoX url rewriter (section <UrlRewrite> in web.config file)

thanks

1
1/21/2013 12:52:51 PM
2218 Reputation 300 Total posts

Hello,

This is a URL rewriting rule you can use to redirect from www.mysite.com to mysite.com for example:

<if header="HOST" match="^(www.mysite.com)$">
  <redirect name="SiteCanonical" url="^(.*)$" to="http://mysite.com$1" />
</if>
Please place this rule at the top of your rewrite section in the web.config.

Regards,
Mario

2
1/21/2013 1:12:34 PM
56 Reputation 7 Total posts

Hi Mario, thank you for your help.
Just one question: does above code set also 301 redirect?
Regards

3
1/21/2013 1:59:32 PM
2218 Reputation 300 Total posts

Hello,

It should set a 301 redirect, however if you wan to be 100% certain you can set the permanent="true" property for example:

<redirect name="SiteCanonical" url="^(.*)$" to="http://test.ie$1" permanent="true" />
Setting this property to false will set a 302 redirect.

Regards,
Mario

4
1/21/2013 2:22:06 PM
56 Reputation 7 Total posts

Great thanks Mario :)

5
2/20/2013 7:17:31 PM
6018 Reputation 709 Total posts

I want my site to redirect from "domain.com" to "www.domain.com" so that my site url remains consistent.

where in webconfig I need to put this <redirect name> tag ? and what exactly I need to put in the tag ? could you please show me what to add and where ?

6
2/20/2013 7:56:34 PM
2218 Reputation 300 Total posts

Hello,

You need to place the following rule at the top of the UrlRewriter section.

Regards,
Mario

7
2/20/2013 8:21:04 PM
6018 Reputation 709 Total posts

Is this correct ?

<if header="HOST" match="^(http://mydomain.com)$"
<redirect name="SiteCanonical" url="^(.*)$" to="http://www.mymydomain.ie$1" permanent="true" />
</if>
 
    <UrlRewriter>
      <default-documents>
        <document>Default.aspx</document>
      </default-documents>

8
2/20/2013 8:11:06 PM
6018 Reputation 709 Total posts

I just tested the above code and getting error on my site:

Server Error500 - Internal server error.There is a problem with the resource you are looking for, and it cannot be displayed.

9
2/20/2013 9:17:48 PM
2218 Reputation 300 Total posts

This would be the correct order:

<UrlRewriter>
<default-documents>
  ...
</default-documents>
<register logger="MonoSoftware.UrlRewriter.Logging.DebugLogger, MonoSoftware.UrlRewriter"/>
 
 <if header="HOST" match="^(www.mydomain.com)$">
  <redirect name="SiteCanonical" url="^(.*)$" to="http://mydomain.com$1" />
</if>
Regards

10
1 2
This is a demo site for MonoX. Please visit Mono Software for more info.