如果不存在以下查询字符串参数,我想将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
发布评论