【问题标题】:force https not working on the index page of my website强制 https 在我的网站的索引页面上不起作用
【发布时间】:2018-12-05 11:28:17
【问题描述】:

如果我输入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

【问题讨论】:

标签: apache .htaccess


【解决方案1】:

尝试添加

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

来源:Redirect All Web Traffic

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多