1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Redirect domain.com to www.domain.com

Redirect domain.com to www.domain.com

3 posts, 0 answered
  1. Jay
    Jay avatar
    51 posts
    Registered:
    16 Jul 2008
    01 Mar 2010
    Link to this post
    Does anyone know an easy way to redirect "domain.com/whatever-folder/whatever-page.aspx" to "www.domain.com/whatever-folder/whatever-page.aspx"?    I tried using ServerVariables to check the server name and url but because of Sitefinity's URL re-writing the server variable for URL always returns cmsentrypoint.aspx.

    I'm just a little concerned about messing around and breaking any of Sitefinity's built in URL re-writing functions.  If anyone has done this before and has an easy fix, I'd appreciate it.
    Thanks
  2. Jay
    Jay avatar
    51 posts
    Registered:
    16 Jul 2008
    01 Mar 2010
    Link to this post
    I think I may have answered my own question. :)
    I added this into my Global.asax and it seems to work okay.  It only checks at the beginning of the session instead of checking on every single page but that seems more efficient anyway.

    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started
        if (!HttpContext.Current.Request.Url.ToString().ToLower().StartsWith("http://www"))
        {
            Response.Redirect("http://www.domain.com" + HttpContext.Current.Request.RawUrl.ToString());
        }
    }

    If anyone has a better way to do this though, I'd be interested.
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    01 Mar 2010
    Link to this post
    Hi Jay,

    You can also use IHttpModule and inside BeginRequest you can replace the url.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
3 posts, 0 answered