强制https在我网站的索引页面上不起作用

时间:2018-12-05 11:28:17

标签: apache .htaccess

如果我输入http://example.com,它将变成http://www.example.com

www重定向有效,但https重定向无效。

但是它在我的文章(home.php)中有效,如果我输入www.example.com/article/1/article-name,它将变为https://www.example.com/article/1/article-name

为什么在index.php上不起作用?

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteRule ^page/(.*) /index.php?pagina=$1
RewriteRule ^article/(.*) /home.php?id=$1

RewriteRule ^sitemap\.xml$ sitemap.php [L]

RewriteCond %{HTTP_HOST} !=""
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

ErrorDocument 404 /404.php

AddCharset UTF-8 .htm
AddCharset UTF-8 .html
AddCharset UTF-8 .php

Options -MultiViews

options -indexes

1 个答案:

答案 0 :(得分:0)

尝试添加

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

来源:Redirect All Web Traffic