重写HTTP到HTTPS仅使用的

重写HTTP到HTTPS仅使用的

本文介绍了重写HTTP到HTTPS仅使用的.htaccess一些网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有关于我的问题很多主题。我检查了所有的,并试图出来,但不能使它发挥作用。我需要重写HTTP到HTTPS上只有一些网页。之后参观https网页的URL会回到HTTP。这是我到目前为止有:

I know there is lots of topics regarding my question. I checked them all and tried them out but can't make it work.I need to rewrite http to https on some pages only. After visiting https pages the URL would go back to http.This is what I have so far:


# Rewrite Rules for domain.com
RewriteEngine On
RewriteBase /

#Rewrite www to domain.com
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

#Rewrite to https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} /secure.php
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

#traffic to http://, except secure.php
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} /secure.php
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

当我跳过最后一组规则(流量为http://,除了secure.php)的secure.php页面加载的HTTPS和加密。精细。随着最后一组规则(流量为http://,secure.php除外)的URL改写为https,变成蓝色(SSL)如属第二和消失(无SSL),但该网址仍是HTTPS

When I skip the last set of rules (traffic to http://, except secure.php) the secure.php page loads as https and is encrypted. FINE. With the last set of rules (traffic to http://, except secure.php) the URL rewrites to https, turns blue (SSL) for a second and disappears (no SSL) but the URL is still https.

你知道吗?亚采

推荐答案

有与第三组规则的错误。这里的解决方案:第3集的规则:如果HTTPS是上,那么如果URL中不包含/安全,然后重定向到HTTP。

There's a mistake with the 3rd set of rules.Here's the solution: with the 3rd set of rules: if the https is "on" then if the URL doesn't contain "/secure" then redirect to http.

# Rewrite Rules for domain.com
RewriteEngine On
RewriteBase /

#Rewrite www to domain.com
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

#Rewrite to https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} /secure.php
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

#traffic to http://, except secure.php
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(/secure.php)
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L]


题外话建议:请认准雅虎慢的网站优化的他们非常聪明的建议,你就会明白为什么它总是最好有www的了。你最好做相反的你#1重写规则:如果没有WWW,然后将其添加


Off topic advice: please look for Yahoo Slow an their very clever advices on website optimisation and you'll see why it's always better to have the "www" before. You'd better do the opposite for your #1 rewrite rule: if there's no "www", then add it.

请尝试使用 RewriteLog 指令:它可以帮助您追踪到这样的问题:

Please try to use the RewriteLog directive: it helps you to track down such problems:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

告诉我,如果它的工作原理。

Tell me if it works.

这篇关于重写HTTP到HTTPS仅使用的.htaccess一些网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 07:19