Trying to redirect from http to https using .htaccess

Posted on 2012-08-29
Last Modified: 2012-08-29
Hi there,

One of my clients purchased a 1-year SSL certificate for one of his sites.  It's a one-click checkout process.  He had some development work done to hook it up to's payment gateway.  Anyways, I registered the certificate and I am currently trying to force a redirect to https if someone tries to access the http URL for the checkout page.

This is what I have :

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule https://%{HTTP_HOST}%{REQUEST_URI}

Open in new window

It's not working as far as I can tell.  I've cleared the browser cache multiple times and it's a no-go.  

Am I doing this right?
Question by:duder78
    LVL 16

    Expert Comment

    Are you sure "mod-rewrite" is enabled in Apache?

    Do you have any other .htaccess files working?

    Also try  either of the below:

    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$  https://%{HTTP_HOST}/$1 [L,NC]

    Open in new window

    - or -
    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond %{HTTPS} off
    RewriteRule ^/checkout.php$  https://%{HTTP_HOST}/checkout.php [L, NC]

    Open in new window

    LVL 7

    Accepted Solution

    Try this:

    RewriteCond %{SERVER_PORT} =80
    RewriteRule ^checkout\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
    LVL 26

    Expert Comment

    Or if your after a rule that will work in either the httpd.conf or a .htaccess file and is not case sensitive try:

    RewriteEngine On
    RewriteCond %{HTTPS}        off
    RewriteCond %{REQUEST_URI}  ^/checkout\.php$        [NC]
    RewriteRule .               https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    Open in new window


    Author Closing Comment

    That did it, perfect.  Thank you.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting ( to http…
    If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now