Tania Rascia

Skip Navigation
Redirect all HTTP requests to HTTPS

Redirect all HTTP requests to HTTPS

 /  1 response

If you have SSL/TLS set up on your server, you might need to force the site to redirect to the secure HTTPS version. If you need to know how to obtain the certificate, read about that here. Otherwise, create an .htaccess file in the root of your server with the following code.

RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

If this causes a “too many redirects” error for you, you can replace RewriteCond %{HTTP:X-Forwarded-Proto} !https with RewriteCond %{HTTPS} !=on.

Note

Hi, my name is Tania Rascia. I've turned down every offer for advertisements or sponsored posts on this website. I write free resources that have helped thousands of people successfully transition into a web development career.

My committment is to no bullshit, no sponsored posts, no ads, and no paywalls. If you enjoy my content, please consider supporting what I do.

Support my work

Newsletter

New articles on web development every two weeks.

Write a response

Your email address will not be published.

All code will be displayed literally.

Discussion