0

I have installed an SSL on my website and I have a .htaccess file that has some conditions already written. I have looked at a number of methods shown online on how to force https. However, none of them seem to work. I keep having broken links.

The code I am currently using, the rule commented out does not work for https

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /

#This condition doesn't seem to work
#RewriteEngine On
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Redirect non www. to www.
#RewriteCond %{HTTP_HOST} !^www\.MYWEBSITE\.co\.uk
#RewriteRule (.*) http://www.MYWEBSITE.co.uk/$1 [R=301,L]

# Remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1? [R=301,L]

# Remove .php ONLY if requested directly
RewriteCond %{THE_REQUEST} (\.php)
RewriteRule ^(.+)\.php /$1 [R=301,L,QSA]

RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
NathanC
  • 19
  • 5
  • Possible duplicate of [http to https through .htaccess](https://stackoverflow.com/questions/10489895/http-to-https-through-htaccess) – Pedram Jan 16 '18 at 12:11

1 Answers1

0

If you would like to force HTTPS you can use the following:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Tachyon
  • 2,171
  • 3
  • 22
  • 46