Rewrite non-SSL URLs to SSL URLs using htaccess

If you are looking to 301 redirect (permanently redirect) all non-SSL URLs to SSL URLs of your website using htaccess then you can add the following lines to your htaccess file.

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The first line checks if https is activated or not. If its not then it will 301 redirect the URL to its respective SSL URL.

Please follow and like us:

Be the first to comment

Leave a Reply

Your email address will not be published.