2
votes

Please provide me with .htaccess syntax to do the following:

  1. Redirect from http to https
  2. Redirect from https://www.domain.com.uk to https://domain.com.uk

I tried the following but it didn't work:

RewriteCond %{HTTP_HOST} ^www.(.*)

RewriteRule ^.*$ https://%1/$1 [R=301,L]

2

2 Answers

1
votes

Try adding the following to your htaccess file in the root folder of your domain.

RewriteEngine on
RewriteBase /

#if not domain.com.uk then redirect to domaim.com.uk
RewriteCond %{HTTP_HOST} !^domain\.com\.uk$ [NC]
RewriteRule .* http://domain.com.uk%{REQUEST_URI} [L,R=301]

#if not https
RewriteCond %{HTTPS} off
#redirect to https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
0
votes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?domain.com.uk
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://domain.com.uk/$1 [R=301,L]

For me this work, just tested. So http://www.domain.com.uk into https://domain.com.uk .