MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

how to remove www and set 301 on urlrewriter  (Mono Support )

Viewed 16796 time(s), 16 post(s) 1/21/2013 11:16:52 AMby deska5
deska5

deska5

1/21/2013 11:16:52 AM
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
This content has not been rated yet. 
56 Reputation 7 Total posts
mzilic

mzilic

1/21/2013 12:52:51 PM
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
Rated 5.00, 2 vote(s). 
2218 Reputation 300 Total posts
deska5

deska5

1/21/2013 1:12:34 PM
Hi Mario, thank you for your help.
Just one question: does above code set also 301 redirect?
Regards
This content has not been rated yet. 
56 Reputation 7 Total posts
mzilic

mzilic

1/21/2013 1:59:32 PM
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
Rated 5.00, 2 vote(s). 
2218 Reputation 300 Total posts
deska5

deska5

1/21/2013 2:22:06 PM
Great thanks Mario :)
This content has not been rated yet. 
56 Reputation 7 Total posts
super

super

2/20/2013 7:17:31 PM
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 ?
This content has not been rated yet. 
6018 Reputation 709 Total posts
mzilic

mzilic

2/20/2013 7:56:34 PM
Hello,

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

Regards,
Mario
This content has not been rated yet. 
2218 Reputation 300 Total posts
super

super

2/20/2013 8:21:04 PM
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>
This content has not been rated yet. 
6018 Reputation 709 Total posts
super

super

2/20/2013 8:11:06 PM
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.
This content has not been rated yet. 
6018 Reputation 709 Total posts
mzilic

mzilic

2/20/2013 9:17:48 PM
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
This content has not been rated yet. 
2218 Reputation 300 Total posts
1 2