Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

http://example.com to http://www.example.com/



11:05 am on Sep 29, 2008 (gmt 0)

5+ Year Member


I have one simple static html website, which i want redirect my domain to www prefix.
http://example.com to http://www.example.com/

Kindly suggest what is the solution? I tried with .htaccess file but it's not working. I think it's hosted in window server.

Is there any option or tools to know on whcih server a site is hosted ?

[edited by: engine at 11:20 am (utc) on Sep. 29, 2008]
[edit reason] Please use example.com [/edit]


4:03 pm on Sep 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Netcraft [netcraft.com] will tell you what web server software your site is running.


4:35 pm on Sep 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Do you have root access?


9:54 pm on Oct 17, 2008 (gmt 0)

10+ Year Member

Here is an custom .NET httpModule that will do what you want.

Imports Microsoft.VisualBasic
Imports System.IO
Imports TheBeerHouse.BLL
Imports System.Web
Imports System.Text.RegularExpressions

Public Class URLRewrite
Implements IHttpModule

Private Shared wwwRegex As New Regex("https?://www\.", RegexOptions.IgnoreCase Or RegexOptions.Compiled)
' Private Shared nonwwwRegex As New Regex("https?://", RegexOptions.IgnoreCase Or RegexOptions.Compiled)

Public Sub Dispose() Implements System.Web.IHttpModule.Dispose

End Sub

Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
AddHandler context.BeginRequest, AddressOf BeginRequest
End Sub

Private Sub BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim app As HttpApplication = CType(sender, HttpApplication)
Dim Request As HttpRequest = app.Request
Dim Response As HttpResponse = app.Response

Dim sRequestedURL As String = Request.Url.ToString.ToLower

Dim bWWW As Boolean = wwwRegex.IsMatch(sRequestedURL)
Dim redirectURL As String = String.Empty
If bWWW Then
redirectURL = wwwRegex.Replace(sRequestedURL, String.Format("{0}://", Request.Url.Scheme))
Do301Redirect(Response, redirectURL)
End If

End Sub

Private Sub Do301Redirect(ByVal Response As HttpResponse, ByVal redirectURL As String)

Response.RedirectLocation = redirectURL
Response.StatusCode = 301

End Sub

End Class


9:18 am on Feb 4, 2009 (gmt 0)

5+ Year Member

ok.. thanks docluv !

But where it should be included ? Is it for all of my webpages or only home page ?


Featured Threads

Hot Threads This Week

Hot Threads This Month