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

Forums / General Discussions / Re-write URL header to avoid SSL issues

Re-write URL header to avoid SSL issues

6 posts, 0 answered
  1. Charles Lee
    Charles Lee avatar
    5 posts
    Registered:
    16 Jul 2009
    09 Sep 2009
    Link to this post
    Is there an easy way to capture URLs that come in as http://MySite.com and rewrite them to http://www.MySite.com? (Add the www.)

    There are sections of our site that use SSL. All links are relative. Our SSL certificate is for www.MySite.com (it includes the www.) As a result, when users who came into the site as http://MySite.com (no www.) go to an SSL section of the site, the URL becomes https://MySite.com - but this doesn' match the certificate (which has the www.) and the browswer throws a warning message.

    A rewrite would need to handle long URLs, but still do the rewrite no matter what page they are on. For example, if they came directly to a page on the site as http://MySite.com/FirstLevel/SecondLevel/Page.aspx it would still be able to rewrite it as http://www.MySite.com/FirstLevel/SecondLevel/Page.aspx

    Ideas on ways to handle this?

    Thanks
  2. Joe
    Joe avatar
    138 posts
    Registered:
    24 Sep 2012
    09 Sep 2009
    Link to this post
    Hi Charles Lee,

    Thanks for contacting us.

    Sitefinity has a custom HTTP module that redirects users to https and http pages. You'd need to override that module, check if the url doesn't contain www (you could use the string.indexof(www) < -1) and replace the url as needed. For more info, take a look at this forum post.

    Kindly let us know if you have any questions.

    Regards,
    Joe
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Armysniper
    Armysniper avatar
    126 posts
    Registered:
    03 Mar 2005
    14 Sep 2009
    Link to this post
    What if the issue is with both SSL and NON SSL pages? How can we handle those situations? Would the same Handler work?
  4. Armysniper
    Armysniper avatar
    126 posts
    Registered:
    03 Mar 2005
    15 Sep 2009
    Link to this post
    I got this to work for basic "missed www" but it wont work in SSL situations. The problem is that if you have users who come to your site with mysite.com/Login.aspx where Login.aspx is an SSL required page...the Handler does not even get triggered. Here is my code...this should help those with other issues:

    1 using System;  
    2 using System.Collections.Generic;  
    3 using System.Linq;  
    4 using System.Web;  
    5 using Telerik.Cms.Web;  
    6 using System.Web.Configuration;  
    7  
    8  
    9 /// <summary> 
    10 /// Handles overrides of SiteFinity HTTP handling. Used to handle WWW and SSL   
    11 /// redirect issues currently.  
    12 /// </summary> 
    13 public class MySiteCmsHttpModule : CmsHttpModule  
    14 {  
    15     protected override void ProcessSslRedirect(HttpContext context, ICmsUrlContext url)  
    16     {  
    17         base.ProcessSslRedirect(context, url);  
    18  
    19         if ((string) WebConfigurationManager.AppSettings["ForceSSLRedirect"] == "true")  
    20         {  
    21             if (context.Request.Url.ToString().IndexOf("www.MySite.org") < 0)  
    22             {  
    23                 string baseUrl = (string) WebConfigurationManager.AppSettings["BaseURL"];  
    24                 if (context.Request.IsSecureConnection)  
    25                 {  
    26                     baseUrl = baseUrl.Replace("http", "https");  
    27                     context.Response.Redirect(baseUrl + context.Request.RawUrl);  
    28                 }  
    29                 else  
    30                     context.Response.Redirect(baseUrl + context.Request.RawUrl);  
    31             }  
    32         }  
    33      }  
    34 }  
    35  

    Notes: The ForceSSLRedirect AppSetting is used for enabling or disabling the code which is good for development code. The BaseURL code is used if you might use this custom module in multiple SiteFinity installations to set the base URL of the site. For example, http://www.mysite.com. You will also notice that I do an IndexOf on the full website. In our site, we handle misspelled names of our site, such as example www.mysit.com would redirect to our site. Having the full site name check you can handle misspells if they are directed to your site.

    Enjoy
  5. Armysniper
    Armysniper avatar
    126 posts
    Registered:
    03 Mar 2005
    15 Sep 2009
    Link to this post
    I was suprised that this module would not trigger on an SSL request before the failure of the certificate does. The cert failure page comes up and THEN the code gets fired. Does not do what we need which is to avoid users from seeing that at all. Any other ideas?
  6. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    16 Sep 2009
    Link to this post
    Hi Armysniper,

    We have just sent you a response in the first, support thread which you have opened. I think it will answer your question.

    Best wishes,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
6 posts, 0 answered