简体   繁体   English

强制https重定向到http重定向,但Wordpress / wp-admin目录除外

[英]Force https to http redirect except for Wordpress /wp-admin directory

Our HTTPS site is indexed on Google. 我们的HTTPS网站已在Google上建立索引。 We need this redirected to HTTP . 我们需要将此重定向到HTTP We're using the following code: 我们正在使用以下代码:

<IfModule mod_rewrite.c>
Options +FollowSymlinks 
RewriteEngine on 
RewriteBase /
RewriteCond %{SERVER_PORT} ^443$ [OR]
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</IfModule>

to redirect https to http , and it works fine. https重定向到http ,它可以正常工作。

However, I want to exclude all of Wordpress admin from the https to http redirect, as I'd like to keep Wordpress admin working over https , so I added: 但是,我想从httpshttp重定向中排除所有Wordpress admin,因为我想让Wordpress admin在https工作,所以我添加了:

RewriteCond %{REQUEST_URI} !^wp-admin 

taking the .htaccess code to: 将.htaccess代码用于:

<IfModule mod_rewrite.c>
Options +FollowSymlinks 
RewriteEngine on 
RewriteBase /
RewriteCond %{SERVER_PORT} ^443$ [OR]
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^wp-admin 
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</IfModule>

Unfortunately this does not work, and trying to load /wp-admin over https results in too many redirects and the Wordpress dashboard does not load. 不幸的是,这不起作用,尝试通过https加载/wp-admin导致重定向过多,并且Wordpress仪表板也无法加载。

www.example.com redirected you too many times. www.example.com重定向您太​​多次。

Would appreciate some help in excluding /wp-admin from the https to http redirect. 希望能将/ wp-admin从https排除到http重定向中提供帮助。

Try the following, this should force everything to HTTP except for the directory wp-admin: 请尝试以下操作,这将强制将所有内容都强制为HTTP,但目录wp-admin除外:

RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{REQUEST_URI} ^\/(wp-admin)
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]

RewriteCond %{HTTP:X-Forwarded-SSL} =on
RewriteCond %{REQUEST_URI} !^\/(wp-admin)
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]

If you have problems with the above, you can try this also: 如果您对上述内容有疑问,也可以尝试以下操作:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/wp-admin
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

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

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

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