【问题标题】:HTTPS rewrite by htaccssHTTPS 由 htaccess 重写
【发布时间】:2018-02-20 16:27:52
【问题描述】:

这是我网站 htaccess 文件中用于 https 的 php 重写代码

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

这是我的问题

我的网站重定向 http://www.example.org --301--> https://www.example.org --301--> https://example.org

由于第一个 (http://www.example.org) 有 400 多个反向链接,最好直接重定向到 https://example.org 并避免中间步骤。

谁能告诉我正确的重写代码?

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    你可以试试这个:

    RewriteEngine on
    
    RewriteCond %{HTTPS} !=on [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule ^(.*)$ https://example.org%{REQUEST_URI} [R=301,L,NE]
    

    【讨论】:

    • 使用新代码,我通过 http:// 请求获得 https://%7Bhttp_host%7D/
    • 所以当您向example.org 发出请求时,您会被重定向到 https://%7Bhttp_host%7D/ 吗?对不起,我不明白这个问题
    • 是的,没错。不知道为什么会这样
    猜你喜欢
    • 2011-07-23
    • 2014-12-11
    • 1970-01-01
    • 2021-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多