I have set up the following within my .htacess file: A redirect from non www to www And http to https
This seems to work fine if I access non www file it will forward to
The problem is, if I access an individual page using non https it'll still render and not forward to https version.
How am I able to correct this? RewriteOptions inherit RewriteEngine on
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mywebsite.co.uk [NC]
RewriteRule ^(.*)$ https://www.myswebsiye.co.uk/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^mywebsite\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.co\.uk$
RewriteRule ^index\.html$ "https\:\/\/www\.mywebsite\.co\.uk\/" [R=301,L]
You can use this to replace both force WWW
and force HTTPs
:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L,NE]
The above code integrates the both, forcing WWW
and forcing HTTPs
.
I have some problem like you, you can edit Your .htaccess to :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.