What to write in htaccess
I want to redirect the different URL to one main URL.
- All variations of the URLs (http://domain.com, https://domain.com, http://www.domain.com) to https://www.domain.com
Thanks in advance.
What to write in htaccess
I want to redirect the different URL to one main URL.
Thanks in advance.
Put this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [L,NE,R=302]
1) Redirect domain.com to www.domain.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
2) http to https
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
Redirect based on port number
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]