.

How to redirect your website url to default https from http How to redirect your website url to default https from http

How to redirect your website url to default https from http


 BY:  CodingTips [  Updated on:Sep-21-2021]    
   Reading Time: About 2 minutes




If you have hosted your website or blog for the first time, you need to buy an SSL certificate to protect the website's privacy and assure your visitors that your website is safe to visit. Usually some hosting providers offer you a free SSL with a hosting plan. If not, you can opt in to buy one for every domain you wish to host. A basic SSL certificate is cheap now where in you can afford to buy it with your hosting plan.

Now we enter to the topic to redirect all your web pages or the entire blog to https. Configuring your website to redirect completely to https is a very important task to perform.

.htaccess redirect http to https:

For example, I have an old url (www1.test.net) and I would like to redirect it to https://www1.test.net
I have implemented and installed our SSL certificate on my site.
This is my old file .htaccess:

RewriteEngine On
RewriteRule !.(js|gif|jpg|png|css|txt)$ public/index.php [L]
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ public/$1 [L]

How can I configure my .htaccess file so that url auto redirect to https?


Here comes the answer:

I use the following to successfully redirect all pages of my domain from http to https:

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

Note this will redirect using the 301 'permanently moved' redirect, which will help transfer your SEO rankings.

To redirect using the 302 'temporarily moved' change [R=302,L]


Leave a Comment


Login to post a public Comment

There are no comments yet. Comment to discuss