重写模块和否定模式的问题
我遇到以下问题:
- 如果网址包含关键字“formulario-”并且它是http连接,我想重定向到https 版本。
- 如果网址不包含关键字“formulario-”并且它是https连接,我想重定向到http版本。
我尝试了以下 .htaccess 但它无法正常工作:
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTPS} !=on
RewriteRule ^formulario-(.*) http://%{HTTP_HOST}%{REQUEST_URI}
感谢您的帮助!
I have the following problem:
- If the url contains the keyword "formulario-" and it is a http connection, I want to redirect to the https version.
- If the url doesn't contain the keyword "formulario-" and it is a https connection, I want to redirecto to http version.
I tried the following .htaccess but it doens't work properly:
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTPS} !=on
RewriteRule ^formulario-(.*) http://%{HTTP_HOST}%{REQUEST_URI}
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
未经测试,但总体思路是:
理论上您不能否定
RewriteRule
,但可以否定RewriteCond
。Untested, but the general idea is:
The theory being you cannot negate a
RewriteRule
, but you can negate aRewriteCond
.到底什么不起作用?
我想到的一件事是:尝试使用 [L] 标志< /a> 用于第一条规则,以便 apache 停止处理第二条规则(如果第一条规则适用)。
但我不确定就是这样。您可能需要某种方法来测试用户之前是否已经重定向。
What exactly does not work?
One thing that comes to mind is: Try using the [L] flag for the first rule, so that apache stops to process the second rule, if the first rule applies.
I am not sure that's it though. You probably need some way to test whether the user was already redirected before.