Redirect URL domain non-www to www .htaccess

Cara mudah dan bekerja secara baik di server VPS linux atau server lainya untuk mengarahkan semua URL domain dari non-www to www adalah sebagai berikut,

Ubah file atau buat pada root folder utama  : .htaccess 

Non SSL Redirect

Redirect Non-www to www (non SSL) permanent [301]

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/\ [R=301,L]

Redirect Non-www to www (non SSL) sementara [302]

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/\ [R=302,L]

Support SSL Redirect

Redicet non-www to www (SSL support https://) permanent [301]

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/\ [R=301,L]

Redicet non-www to www (SSL support https://) sementara [302]

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/\ [R=302,L]

Note : letakan kode paling atas pada file .htaccess sehingga kode berjalan secara maksimal.

READ :  Cara Seting Pembayaran Google Ads (Adword) dengan PAYPAL