简体   繁体   English

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

[英]Redirect one Wordpress page from HTTPS to HTTP

I have checked all of the related questions I can find in here (and in Google in general), and tried all of the various solutions given, but haven't been able to get this to work. 我已经检查了所有可以在这里找到的相关问题(以及整个Google),并尝试了给出的所有各种解决方案,但未能使其正常工作。

I am working on a Wordpress site that has recently gone SSL. 我正在最近使用SSL的Wordpress网站上工作。 I have set it up so that all pages are forced to https by adjusting the Settings page in the Admin area, adding the appropriate line to the wp-config file to force the admin side to be https and have modified my htaccess files to the following: 我已经进行了设置,以便通过调整“管理”区域中的“设置”页面,将适当的行添加到wp-config文件以将管理端强制为https,并将所有htaccess文件修改为以下内容,从而将所有页面都强制为https :

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

Here's what I would like this to do... 这就是我想要做的...
1) http://www.example.com/ (and any sub pages except branding) gets redirected to https://example.com 1) http://www.example.com/ (以及品牌以外的所有子页面)都重定向到https://example.com
2) http://example.com/branding stays as it is 2) http://example.com/branding保持不变
3) https://example.com/branding is redirected to http://example.com/branding 3) https://example.com/branding重定向到http://example.com/branding

The above htaccess code works to force the http: to https:, however, if I enter either http://example.com/branding or https://example.com/branding I am redirected to https://example.com . 上面的htaccess代码可将http:强制为https :,但是,如果我输入http://example.com/brandinghttps://example.com/branding ,则会将我重定向到https://example.com

I have used numerous variations of the initial Rewrite code and placed it in various places (as instructed in various other answers to similar questions here) with no change to the result. 我使用了许多初始Rewrite代码的变体,并将其放置在各个位置(如此处对类似问题的各种其他答案所述),结果没有变化。

If anyone can tell me where my error is and how to fix it, it would be much appreciated. 如果有人可以告诉我我的错误在哪里以及如何解决它,将不胜感激。

Try this: 尝试这个:

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$1 [R=301,L]

With the help of a colleague, we got it worked out. 在同事的帮助下,我们得以解决。 Here's the updated code... 这是更新的代码...

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]

The WP-specific rules in the htaccess file cause some strange situations to occur. htaccess文件中特定于WP的规则导致某些奇怪的情况发生。 The main one being that there is an internal rewrite from /branding/ to /index.php, and then WP handles the request within the PHP. 主要的原因是内部存在从/ branding /到/index.php的重写,然后WP在PHP中处理请求。 The file checks will handle the check to ensure that the index.php file exists. 文件检查将处理检查,以确保index.php文件存在。 WP will internally deal with redirecting valid page requests that don't have trailing slashes. WP将在内部处理重定向没有尾部斜杠的有效页面请求。

Been searching for this for hours... Here is the tweak if you need to redirect more than one page to http from https. 数小时以来一直在搜索...如果您需要将多个页面从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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM