将一个 Wordpress 页面从 HTTPS 重定向到 HTTP

Redirect one Wordpress page from HTTPS to HTTP

我已经检查了我可以在此处找到的所有相关问题(通常在 Google 中),并尝试了所有给出的各种解决方案,但无法使它起作用.

我正在处理最近采用 SSL 的 Wordpress 网站。我已将其设置为通过调整管理区域中的设置页面将所有页面强制为 https,将适当的行添加到 wp-config 文件以强制管理端为 https 并将我的 htaccess 文件修改为以下内容:

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

RewriteCond %{HTTPS} on
RewriteRule ^branding/ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


# 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

这是我希望它执行的操作...
1) http://www.example.com/(以及除品牌之外的任何子页面)被重定向到 https://example.com
2) http://example.com/branding 保持原样
3) https://example.com/branding 重定向到 http://example.com/branding

上面的 htaccess 代码用于强制 http: 到 https:,但是,如果我输入 http://example.com/brandinghttps://example.com/branding,我将被重定向到 https://example.com

我使用了初始重写代码的多种变体并将其放置在不同的地方(按照此处对类似问题的各种其他答案中的说明),结果没有改变。

如果有人能告诉我我的错误在哪里以及如何解决,将不胜感激。

试试这个:

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


RewriteCond %{HTTPS} on
RewriteRule ^branding(.*) http://%{HTTP_HOST}/branding [R=301,L]

在一位同事的帮助下,我们解决了这个问题。这是更新后的代码...

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/branding/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/branding/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

htaccess 文件中的 WP 特定规则导致出现一些奇怪的情况。主要的是有一个内部重写从 /branding/ 到 /index.php,然后 WP 在 PHP 中处理请求。文件检查将处理检查以确保 index.php 文件存在。 WP 将在内部处理重定向没有尾部斜杠的有效页面请求。

已经搜索了几个小时...如果您需要将 多个页面 从 https 重定向到 http,请进行调整。

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/page1|page2|page3/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/page1|page2|page3/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]