Never do anything security related using javascript. Also why do you want to see something in the console? Anyway, you normally handle this using server-side code. Want you want to do is modify the httpRequestBegin pipeline and inject your own step. Create a class called HttpsRedirector
using Sitecore.Pipelines.HttpRequest;
namespace YourNamespace.httpRequestBegin
{
public class HttpsRedirector : HttpRequestProcessor
{
public override void Process(HttpRequestArgs args)
{
if (!args.Context.Request.IsSecureConnection)
{
string url = string.Format("https://{0}{1}", args.Context.Request.Url.Authority, args.Context.Request.RawUrl);
Sitecore.Diagnostics.Log.Info(string.Format("Redirecting to secure connection for '{0}'", url), this);
args.Context.Response.RedirectPermanent(url);
args.AbortPipeline();
}
}
}
}
Create a config file in the "App_Config/Include" folder called httpRequestBegin.config (doesn't really matter what you call it)
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<httpRequestBegin>
<processor type="YourNamespace.HttpsRedirector, YourAssemblyName" patch:before="*[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"/>
</httpRequestBegin>
</pipelines>
</sitecore>
</configuration>