Html 如何使用 htaccess 强制 http-not https

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10356019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:01:34  来源:igfitidea点击:

How to force http- NOT https using htaccess

htmlwordpresshttp.htaccesshttps

提问by JROB

I have ONE directory for my entire domain that I want to force https, which is "/docs". In the /docs folder, I have the following htaccess file:

我的整个域有一个目录,我想强制使用 https,即“/docs”。在 /docs 文件夹中,我有以下 htaccess 文件:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This is forcing https to everything in the /docs directory, which is what I want it to do. The problem I am having is trying to force REMOVE https back to http for all other areas of my site. In the root folder of the site (which is running wordpress), I have the following htaccess file:

这迫使 https 访问 /docs 目录中的所有内容,这正是我想要它做的。我遇到的问题是试图强制 REMOVE https 返回到我网站的所有其他区域的 http。在站点(运行 wordpress)的根文件夹中,我有以下 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
RewriteCond %{REQUEST_URI} !^/docs/?.*$
RewriteRule ^(.*)$ http://www.mydomain.com/ [R=301,L]

Unfortunately, this is not working. I can still access other areas of my site over https.

不幸的是,这不起作用。我仍然可以通过 https 访问我网站的其他区域。

What do I need to change to get this to work correctly?

我需要更改什么才能使其正常工作?

采纳答案by Reza S

Why do you need to revert back to http? If you have the proper SSL certificates you might as well keep your access secure. Unless you are concerned about the load on your system.

为什么需要恢复到http?如果您拥有正确的 SSL 证书,您不妨确保您的访问安全。除非您担心系统上的负载。

I know this is not answering the question, but I want to emphasize that the question is asking on how to do a bad practice, which shouldn't be done in the first place.

我知道这不是在回答问题,但我想强调的是,问题是询问如何做不好的做法,首先不应该这样做。

回答by rog

Since the accepted answer doesn't actually answer the question, I figured I'd post my solution to this. Add this to your .htaccessfile to force HTTP instead of HTTPS:

由于接受的答案实际上并没有回答这个问题,我想我会发布我的解决方案。将此添加到您的.htaccess文件以强制使用 HTTP 而不是 HTTPS:

# BEGIN Force HTTP
RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ http://yourdomain.com/ [R=301,L]
# END Force HTTP

回答by phocks

The "WordPress Force HTTP" plugin was the only thing that worked for me. It changes https to http for not just the front page like most of the answers out there, but also changes https to http for all sub-directories in your website.

“WordPress Force HTTP”插件是唯一对我有用的东西。它不仅像大多数答案一样将首页的 https 更改为 http,还将您网站中所有子目录的 https 更改为 http。

https://en-au.wordpress.org/plugins/wp-force-http/

https://en-au.wordpress.org/plugins/wp-force-http/

回答by Balsever

Try the Force non-SSL plugin for wordpress.

试试 Wordpress 的 Force non-SSL 插件。