htaccess - How to redirect all http (port 80) requests to https (port 443)

Sometimes you may need to redirect http requests on port 80 to (https) on port 443. This can easily be accomplished with .htaccess.

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

4 comments for htaccess - How to redirect all http (port 80) requests to https (port 443)

vaseem ansari's picture

the trick is not working on...

the trick is not working on my local server
i have tested it on my home pc but it is not working can u suggest me what may be the problem

Richard's picture

Vaseem, make sure you have...

Vaseem, make sure you have mod rewrite enabled. You may be able to do this on a local server though, I've never tried.

Sanil's picture

How to i change in my...

How to i change in my localhost setting?
for example my drupal site points to http://{MY_IP}/~sanil/drupal

Azeem Michael's picture

thanks Richard. Always...

thanks Richard. Always learning new things on your blog/~azeem michael

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.