+1 vote

Ive had a look through existing questions, but I havent really come across anything which works for me.

Im currently running a site with a Secure SSL certificate. It can be accessed at https://www.example.co.uk a problem is the site can also be accessed at http://www.example.co.uk - I dont want this to be possible. I need it to redirect from http to https.

I found this one snippet of code to use in an .htaccess file.

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

This works fine when the user enters example.co.uk into their address bar, but I also need to add a conditional statement of some sort so that if the user enters www.example.co.uk or http://www.example.co.uk.

Ive tried using the likes of [OR], but this ends up creating server errors.

Any help and suggestions is appreciated.


in SEO by

1 Answer

0 votes
Best answer

Add the following code in .htaccess file.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

change example.com with your website domain.