重写模块和否定模式的问题

发布于 2024-09-12 01:32:22 字数 538 浏览 2 评论 0原文

我遇到以下问题:

  • 如果网址包含关键字“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

太阳男子 2024-09-19 01:32:22

未经测试,但总体思路是:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule formulario- https://%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !formulario-
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]

理论上您不能否定 RewriteRule,但可以否定 RewriteCond

Untested, but the general idea is:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule formulario- https://%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !formulario-
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]

The theory being you cannot negate a RewriteRule, but you can negate a RewriteCond.

友欢 2024-09-19 01:32:22

到底什么不起作用?

我想到的一件事是:尝试使用 [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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文