【发布时间】:2014-12-13 03:32:42
【问题描述】:
我是 htaccess 重定向的新手,但想做一些特别的事情 - 我不知道推荐的方法是什么,也不知道这是否仍然可行。
我的 .htaccess 文件中有这个:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
现在每个 URL 都被重定向到 HTTPS 版本 - 这很好,也很有必要。但现在有一些例外。
例如,这些 url 必须是 HTTP 而不是 HTTPS:
http://www.mywebsite.com/another/url/which/has/to/be/http
http://www.mywebsite.com/and_again?var=a
是否可以使用 htaccess 解决此问题,如果可能,您可以向我发送参考链接或描述如何执行此操作。
编辑
我现在有这个代码:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !\s/+(/commerce_paypal/*)\s [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
目标是 每个 (!) url 都被重定向到 HTTPS,但开头有 commerce_paypal 的任何 url 除外。
例如:
mydomain.com/commerce_paypal <- http
mydomain.com/commerce_paypal/smth/else <- http
mydomain.com/what/ever <- https
【问题讨论】:
标签: regex apache .htaccess mod-rewrite redirect