.htaccess重定向到HTTP,如果url包含字符串


.htaccess redirect to http if url contains string

我正在尝试配置我的htaccess,以便如果我的网站中的URL包含Buy,Rent,Make-offer,Sold将https请求重定向到http

这是我尝试过的,没有运气

# Redirect other HTTPS requests to plain HTTP
RewriteCond %{HTTPS} on
RewriteRule ^(buy|rent|sold|make-offer)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]

有人能帮帮我吗?

您的匹配模式包含字符串锚(^$)的开始和结束,因此只匹配//host/buy等url。如果你想要开始然后放弃$,如果你想要包含,然后放弃两者。如果您想要"包含单词buy…",则使用

  RewriteRule 'b(buy|rent|sold|make-offer)'b http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]

等。