Cara redirect HTTP ke HTTPS Apache dan Nginx

Panduan cara redirect HTTP ke HTTPS untuk web server Apache dan Nginx. Pada tutorial mengalihkan http ke https ini, saya beranggapan sertifikat SSL sudah terinstall di server/hosting.

Konfigurasi .htaccess redirect ke HTTPS untuk Apache

Copy/paste kode berikut ke dalam file .htaccess untuk redirect http ke https

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

Konfigurasi server block Nginx

Copy/paste kode berikut pada file konfigurasi server block Nginx

server {
   listen 80;
   server_name idnetter.com www.idnetter.com;
   return 301 https://$server_name$request_uri;
}

Jangan lupa restart Nginx

Add a comment