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 )

19025 put(a) pogledan, 16 odgovor(a) 21.1.2013. 11:16:52Kreirao(la) deska5
deska5

deska5

21.1.2013. 11:16:52
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
Ovaj sadržaj još nije ocijenjen. 
56 Reputacija 7 Ukupno objava
mzilic

mzilic

21.1.2013. 12:52:51
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
Ocjena 5,00, 2 glas(ova). 
2218 Reputacija 300 Ukupno objava
deska5

deska5

21.1.2013. 13:12:34
Hi Mario, thank you for your help.
Just one question: does above code set also 301 redirect?
Regards
Ovaj sadržaj još nije ocijenjen. 
56 Reputacija 7 Ukupno objava
mzilic

mzilic

21.1.2013. 13:59:32
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
Ocjena 5,00, 2 glas(ova). 
2218 Reputacija 300 Ukupno objava
deska5

deska5

21.1.2013. 14:22:06
Great thanks Mario :)
Ovaj sadržaj još nije ocijenjen. 
56 Reputacija 7 Ukupno objava
super

super

20.2.2013. 19:17:31
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 ?
Ovaj sadržaj još nije ocijenjen. 
6018 Reputacija 709 Ukupno objava
mzilic

mzilic

20.2.2013. 19:56:34
Hello,

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

Regards,
Mario
Ovaj sadržaj još nije ocijenjen. 
2218 Reputacija 300 Ukupno objava
super

super

20.2.2013. 20:21:04
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>
Ovaj sadržaj još nije ocijenjen. 
6018 Reputacija 709 Ukupno objava
super

super

20.2.2013. 20:11:06
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.
Ovaj sadržaj još nije ocijenjen. 
6018 Reputacija 709 Ukupno objava
mzilic

mzilic

20.2.2013. 21:17:48
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
Ovaj sadržaj još nije ocijenjen. 
2218 Reputacija 300 Ukupno objava
1 2