W3Schools Learner's Blog

W3Schools Programming knowledge summary website

div

2/15/2020

redirect http to https in apache server( .htaccess)

Why should we use https website?

We used to use http in our website, but now, the https is becomming more and more popular, and Search Engines treat https are more friendly than http.

So we need to redirect http to https website when some people access our websites.

But how to redict http to https in our apache server?

It's very easy, we just need to add .htaccess file in our web root directory, and add some code, as follows:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [R=301,L]
Then we need to restart our apache server.

Remarks:

If you don't know how to configure SSL certificate by yourself, you can click here: SSL Certificate Configure Tutorial

No comments:

Post a Comment

Note: only a member of this blog may post a comment.