通过htaccess文件强制http到https,无法正常工作

时间:2018-05-16 10:49:09

标签: php html .htaccess ssl ssl-certificate

所以我的问题是如果我访问我的网站它是不安全的。但是,如果我放https://www.websitename.co.uk,它将显示带有https和安全栏的网站。但是,当我上传我的htaccess文件时,网站并不想连接。

Error message when I use the htaccess

如果我从htaccess文件中注释掉下面的代码,那么该网站可以正常运行,但不会显示安全性。如果我添加该代码,它只是给我错误消息,如图中所示。

 # Redirect http to https editor nathan 18/01/2017
    #RewriteEngine On
    #RewriteCond %{HTTPS} off
    #RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

htaccess文件

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /

# Redirect http to https editor nathan 18/01/2017
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

1 个答案:

答案 0 :(得分:0)

请更改此行:

menu.xml

进入这个:

marked as duplicate

这意味着如果访问者转到http(即端口80)将重定向到https(这是443)