【问题标题】:Domain redirirection to https issue域重定向到 https 问题
【发布时间】:2019-08-20 13:05:41
【问题描述】:

我的域重定向有问题。 它是 wordpress,我想将所有非安全 url 重定向到安全

地址栏输入http://www.my-domain.com时重定向到https://www.www.my-domain.com的问题 (它增加了一个额外的 www)

这是我在 .htaccess 文件中的重定向部分:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]


    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
    RewriteRule (.*) https://www.%1/$1 [R=301,L]
</IfModule>

我做错了什么?

【问题讨论】:

  • 正在添加额外的 www:RewriteRule (.*) https://www.%1/$1 [R=301,L] - %1 是匹配的主机名,并且已经是 www.my-domain.com

标签: wordpress .htaccess ssl redirect


【解决方案1】:

此代码为我工作

     # BEGIN WordPress
    <IfModule mod_rewrite.c>

    RewriteOptions inherit
    RewriteEngine on
    Header set content-Security-Policy: upgrade-insecure-requests
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress

【讨论】:

    猜你喜欢
    • 2011-06-26
    • 2015-09-08
    • 2014-01-30
    • 2019-09-25
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    相关资源
    最近更新 更多