【问题标题】:Wordpres - redirect my templates 404.php page to https using htaccessWordpress - 使用 htaccess 将我的模板 404.php 页面重定向到 https
【发布时间】:2020-01-24 21:53:14
【问题描述】:

在我的 wordpress 网站上的普通链接上,用户总是得到 https。但是,当用户键入一些不存在的页面时,我的网站可以同时使用 http 和 https。

例如:

访问者在 mypage.com/non-existing-page 中输入,他得到 404.php 页面模板,但是 404.php 页面模板可以通过 http 和 https 访问。

我想要做的是将http://mypage.com/non-existing-page 重定向到https://mypage.com/non-existing-page

我的 htaccess 文件

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

# END WordPress
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]

【问题讨论】:

    标签: php wordpress .htaccess


    【解决方案1】:

    .htaccess 中的最后一条规则是将非 HTTPS 流量重定向到 HTTPS 版本。我认为您需要在 Wordpress 规则之前将这些行移到顶部。这是我过去使用的强制 HTTPS 规则:

    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
    

    【讨论】:

    • 将我最后的规则移到顶部并且工作正常。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-08
    • 1970-01-01
    • 2014-03-30
    • 2018-08-31
    相关资源
    最近更新 更多