Forum Moderators: open

Message Too Old, No Replies

Remove www from header

         

andrewsmd

7:27 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a site with an ssl certificate. However, the ssl cert is only good for domain.com not www.domain.com. How do I redirect either via IIS or VB in my master page. What I would want to do is just say any request that comes in www.domain.com should go to domain.com. Any suggestions on how to do this? Thanks,

marcel

7:50 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could query the URL in the global.asax BeginRequest, and redirect if necessary, ie:

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
If Request.Url.AbsoluteUri.ToLower.StartsWith("http://www") Then
Dim newUrl As String = Request.Url.AbsoluteUri.ToLower.Replace("http://www", "http://")
Response.Status = "301 Moved Permanently"
Response.AddHeader("location", newURL)
End If
End Sub

With IIS7 rewrite module you can add the following to your web.config file:


<rule name="Redirect to non WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.example.com$" />
</conditions>
<action type="Redirect" url="http://example.com/{R:0}" redirectType="Permanent" />
</rule>

Or use something like urlrewriter.net

andrewsmd

8:15 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm using IIS 6 is there a way to do that there, or possibly in dns manager? Thanks for your help.

marcel

8:18 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm using IIS 6 is there a way to do that there, or possibly in dns manager?

Not that I know of, but the code I posted will work in IIS6, or a plugin like urlrewriter.net or ISAPI_Rewrite.

Edit: I forgot to add, the code I posted will also work in a master page, but I prefer using Global.asax for this.

andrewsmd

8:38 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, I tried the code and it worked thanks. I just wondered if there was a way to do it in IIS. Thanks though.