本文介绍了htaccess的重写规则:根据输入的URL重定向HTTP到HTTPS或https到http(双向)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 有谁请帮我写重写规则,重定向HTTP&LT; - > HTTPS(回力取决于输入网址)这些条件: 1) http://www.mydomain.com,http://www.mydomain.com/?p=home,http://www.mydomain.com/?p=home1 ,http://www.mydomain.com/?qqq=home 总是HTTP,即使HTTPS的类型,而不是http。 2)所有其他页面总是HTTPS,即使HTTP被输入代替https。在code以下重定向所有的URL(并保持参数),除非 http://www.mydomain.com ,到https。 #redirects HTTP到HTTPS如果有参数的RewriteCond%{} HTTPS关闭的RewriteCond%{QUERY_STRING}!^ $重写规则HTTPS(*)://%{HTTP_HOST}%{REQUEST_URI}我试过之后,code添加下面右侧的code以上重定向HTTPS访问http以及(如果没有参数应用),这样所有的页面总是HTTPS,除了www.mydomain .COM,但我有没有运气。此外,我错过了P =回家,P =和home1,QQQ =家庭 - ???我不知道如何将它们添加 的RewriteCond%{HTTP}关闭的RewriteCond%{QUERY_STRING} ^ $(。*)重写规则的http://%{HTTP_HOST}%{REQUEST_URI}解决方案 尝试添加以下到您的网站的根目录下的htaccess文件。 RewriteEngine叙述上的RewriteBase /#determine如果页被认为是http#如果它具有p =家庭或P =和home1或QQQ =家在查询字符串的RewriteCond%{QUERY_STRING}(^ |&安培;)(P =和home1 | QQQ =回家吗?)(安培; | $)[NC,OR]#or如果查询字符串是空的的RewriteCond%{QUERY_STRING} ^ $#设置的环境变量,以1重写规则^ - [E = IS_HTTP:1]#ALL的网页,都应该是HTTP,如果HTTPS重定向的RewriteCond%{} HTTPS上的RewriteCond%{ENV:IS_HTTP} 1重写规则^ HTTP://%{HTTP_HOST}%{REQUEST_URI} [R,L = 301]#ALL其他页面发送到HTTPS如果尚未如此的RewriteCond%{} HTTPS关闭的RewriteCond%{ENV:IS_HTTP} 1!重写规则^ https://开头%{HTTP_HOST}%{REQUEST_URI} [R,L = 301] Could anybody please help me to write rewriterule, that redirects http<->https (back and force depending of URL typed) with these conditions:1) http://www.mydomain.com , http://www.mydomain.com/?p=home , http://www.mydomain.com/?p=home1 , http://www.mydomain.com/?qqq=home are always http, even if https are typed instead of http.2) all the rest pages are always https, even if http was typed instead of https.The code below redirects all urls (and keeps parameters), except http://www.mydomain.com , to https.#redirects http to https if there are parametersRewriteCond %{HTTPS} offRewriteCond %{QUERY_STRING} !^$RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}I've tried to add the code below right after the code above to redirect https to http as well (if there are no parametres), so that all pages are always https, except www.mydomain.com, but I had no luck. Also I missed ?p=home, ?p=home1, ?qqq=home - I don't know how to add them.RewriteCond %{HTTP} offRewriteCond %{QUERY_STRING} ^$RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} 解决方案 Try adding the following to your htaccess file in the root directory of your site.RewriteEngine onRewriteBase /#determine if page is supposed to be http#if it has p=home or p=home1 or qqq=home in querystringRewriteCond %{QUERY_STRING} (^|&)(p=home1?|qqq=home)(&|$) [NC,OR]#or if query string is emptyRewriteCond %{QUERY_STRING} ^$#set env var to 1RewriteRule ^ - [E=IS_HTTP:1]#all pages that are supposed to be http redirected if httpsRewriteCond %{HTTPS} onRewriteCond %{ENV:IS_HTTP} 1RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R,L=301]#all other pages are sent to https if not already soRewriteCond %{HTTPS} offRewriteCond %{ENV:IS_HTTP} !1RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L=301] 这篇关于htaccess的重写规则:根据输入的URL重定向HTTP到HTTPS或https到http(双向)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-06 13:36