Developer

301 redirects with .htaccess website tips

By July 30, 2017 No Comments

Force ‘www’ on domain

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

http to https


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

Best Solution

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

Source: https://stackoverflow.com/questions/29029049/best-practice-301-redirect-http-to-https-standard-domain

Generators for .htaccess

Leave a Reply