Redirect HTTP to HTTPS

This little trick will show you how to configure Apache to automatically redirect HTTP requests to HTTPS, i.e. http://www.karkomaonline.com to https://www.karkomaonline.com.

Add this directives to you configuration file:

RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [L,R]

One Response to “Redirect HTTP to HTTPS”

  1. anonymous says:

    This was the best advice on this topic I found.

    Just a note:

    Remember, if you put these rules in the main server conf file (usually httpd.conf) rather than an .htaccess file, you’ll need to use ^/… … instead of ^… … at the beginning of the RewriteRule line, in other words, add a slash.

    … and the opposite is as well truth.

    Took me almost an hour to get my redirection working, until I deleted the slash at the beginning of the rewrite rule to:

    RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [L,R]

    Hope this helps someone.

    ccho.

Leave a Reply

You must be logged in to post a comment.