如果通过htaccess不存在querystring参数,则将HTTPS重定向到HTTP

编程入门 行业动态 更新时间:2024-10-09 16:29:29
本文介绍了如果通过htaccess不存在querystring参数,则将HTTPS重定向到HTTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果不存在以下查询字符串参数,我想将HTTPS重定向到HTTP only :

I would like to redirect HTTPS to HTTP only if the following querystring parameters are absent:

www.example/index.php?p=login www.example/index.php?p=signup www.example/index.php?p=cart www.example/index.php?p=one_page_checkout

www.example/index.php?p=login www.example/index.php?p=signup www.example/index.php?p=cart www.example/index.php?p=one_page_checkout

也就是说,除此以外的任何查询字符串 other 都应从HTTPS重定向到HTTP.我想确保只有我的结帐路径是HTTP.

That is, any querystring other than these should redirect from HTTPS to HTTP. I want to make sure only my checkout path is HTTP.

可以简单地将.htaccess与RewriteCond和RewriteRule一起使用吗?

Can this be done simply using .htaccess with RewriteCond and RewriteRule?

推荐答案

将其添加到文档根目录中的htaccess文件中,最好在可能已经存在的所有规则之上:

Add this to the htaccess file in your document root, preferably above any rules that may already be there:

RewriteEngine On RewriteCond %{QUERY_STRING} !(^|&)p=(login|signup|cart|one_page_checkout)(&|$) RewriteCond %{HTTPS} on RewriteRule ^index\.php$ %{HTTP_HOST}%{REQUEST_URI} [L,R] RewriteCond %{QUERY_STRING} (^|&)p=(login|signup|cart|one_page_checkout)(&|$) RewriteCond %{HTTPS} off RewriteRule ^index\.php$ %{HTTP_HOST}%{REQUEST_URI} [L,R]

要使其成为永久重定向,请在方括号中的R之后添加=301.

To make this a permanent redirect, add a =301 after the R in the square brackets.

更多推荐

如果通过htaccess不存在querystring参数,则将HTTPS重定向到HTTP

本文发布于:2023-11-01 11:12:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549182.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在   则将   重定向   参数   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!