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

查看:319
本文介绍了使用的.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.

有谁知道怎么才能始终强制正确使用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.

我有一个环顾四周SO也没有找到合适的答案。

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

推荐答案

我用类似的措施,以字为preSS我的管理文件夹:

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对部分可能不适用于所有Web服务器的工作。我的虚拟主机提供商需要的RewriteCond%{HTTP:X-转发,SSL}。在,例如

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]

如果你想一些替代的方法来做到这一点,看看 askapache

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

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

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