使用 .htaccess 在 HTTP 和 HTTPS 之间正确切换 [英] Correctly switching between HTTP and HTTPS using .htaccess

查看:31
本文介绍了使用 .htaccess 在 HTTP 和 HTTPS 之间正确切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个购物网站,我们将其托管在共享主机(Mediatemple Gridserver)上.网站的某些部分需要使用 HTTPS(结帐等),但其余部分应该使用 HTTP.

We've got a shopping site which we're hosting on a shared host (Mediatemple Gridserver). Some parts of the site need to use HTTPS (checkout etc) but the rest should be using HTTP.

有谁知道我们如何始终强制对特定 URL 正确使用 HTTP/HTTPS?我们已经让它在各种状态下工作,但我们无法收到一个页面的请求,该页面应该在 HTTP 上,但通过 HTTPS 请求正确切换回来.

Does anyone know how we can always force the correct use of HTTP/HTTPS for particular URLs? We've had it working in various states but we can't get a request for a page that should be on HTTP but is requested with HTTPS to switch back correctly.

我环顾四周,但找不到合适的答案.

I've had a look around SO but couldn't find a suitable answer to this.

推荐答案

我在 wordpress 的 admin 文件夹中使用了类似的东西:

I use something similar to this for my admin folder in wordpress:

#redirect all https traffic to http, unless it is pointed at /checkout
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/checkout/?.*$
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]

RewriteCond %{HTTPS} on 部分可能不适用于所有网络服务器.例如,我的虚拟主机需要 RewriteCond %{HTTP:X-Forwarded-SSL} on.

The RewriteCond %{HTTPS} on portion may not work for all web servers. My webhost requires RewriteCond %{HTTP:X-Forwarded-SSL} on, for instance.

如果您想强制反向,请尝试:

If you want to force the reverse, try:

#redirect all http traffic to https, if it is pointed at /checkout
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/checkout/?.*$
RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]

如果您想要一些替代方法,请查看 问阿帕奇.

If you want some alternate ways to do it, check out askapache.

这篇关于使用 .htaccess 在 HTTP 和 HTTPS 之间正确切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆