Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
This code makes a permanent redirect from any other hostname to the specified hostname to the same page. I usually use to ensure that Google (and others) does not index the same content twice.
In effect:
https://domain.dk:3837/mysubpage.aspx redirects to https://www.domain.dk/3837/mysubpage.aspx
<% string primaryAddr = "www.whatever.dk"; var uri = HttpContext.Current.Request.Url; if (uri.Host != primaryAddr || uri.Host.Contains(".local")) { string newurl = uri.Scheme + @"://" + primaryAddr; if (uri.Port != 80) newurl += ":" + uri.Port; newurl += uri.PathAndQuery; HttpContext.Current.Response.Status = "301 Moved Permanently"; HttpContext.Current.Response.AddHeader("Location",newurl); }%>
Does this exsist in a package already or should I make it?
/Jesper
Hi Jesper,
I typically achieve this using an IIS rewrite rule for "canonical domain name"
<rewrite> <rules> <rule name="CanonicalHostNameRule1"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^www\.mydomain\.com$" negate="true" /> </conditions> <action type="Redirect" url="http://www.mydomain.com/{R:1}" /> </rule> </rules> </rewrite>
Mike also posted an example on his blog of how to do this and some others also: umbraco.miketaylor.eu/.../
But actually, I just noticed that your code handles ports and SSL, which I'm not sure how that works in IIS. So maybe it could be useful :)
-Tom
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Primary address redirect
This code makes a permanent redirect from any other hostname to the specified hostname to the same page. I usually use to ensure that Google (and others) does not index the same content twice.
In effect:
https://domain.dk:3837/mysubpage.aspx redirects to https://www.domain.dk/3837/mysubpage.aspx
Does this exsist in a package already or should I make it?
/Jesper
Hi Jesper,
I typically achieve this using an IIS rewrite rule for "canonical domain name"
Mike also posted an example on his blog of how to do this and some others also: umbraco.miketaylor.eu/.../
But actually, I just noticed that your code handles ports and SSL, which I'm not sure how that works in IIS. So maybe it could be useful :)
-Tom
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion