【问题标题】:HTTPS Redirection fixing multiple 301 redirectHTTPS 重定向修复多个 301 重定向
【发布时间】:2022-01-02 07:45:45
【问题描述】:

我想将所有请求重定向到https://www.example.com

ht访问代码:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} !https 
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

我当前的代码工作正常,但是当有人输入 http://example.com 时,它需要两个 301 redirect 意味着它首先重定向到 https://example.com 而不是 https://www.example.com

我想要 http://example.comhttps://www.example.com 和一个 301 redirect

【问题讨论】:

    标签: html .htaccess ssl redirect https


    【解决方案1】:

    您可以使用以下命令在单个请求中将所有请求重定向到https://www

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP:X-Forwarded-Proto} !https 
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} !^www
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
    RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301]
    

    确保在测试此新重定向之前创建浏览器缓存数据。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    • 2017-09-21
    • 1970-01-01
    相关资源
    最近更新 更多