Javascript Recipe - Redirect http to secure https URLs on the fly

Javascript Recipe - Redirect http to secure https URLs on the fly

03/17/08 | by admin [mail] | Categories: Nerd Thoughts

This code, when embedded in your HTML page, will automatically redirect visitors to the secure version of your page provided that SSL is set up on your server. The code requires no customization. It does not pass along request variables so you should use this on your “secure form” page.

Code:

<script language="JavaScript">
loc=top.location.href;
if(! loc.match(/^https/)){
loc=loc.replace(/^http:/,"https:");
top.location.href=loc;
}
</script>

Of course, ensuring your form data is encrypted on its way to storage or a recipient is another story. I’ll post how to do that if anyone asks.

Comments, Pingbacks:

No Comments/Pingbacks for this post yet...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))

Matthew Steven's Thought Box

Matthew Steven is a lifelong technology enthusiast. He has been in the business of creating ecommerce web applications, solving problems on UNIX platforms, and hosting servers since the earliest days of the internet. He is active in community service, plays classical guitar, and has a number of furry children.

July 2008
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Linkblog

b2evolution

  • Matt's Org

    Dig the dirt on Matthew Steven at his homepage.

    Permalink

Misc

XML Feeds

What is RSS?

powered by b2evolution free blog software