【发布时间】:2012-01-20 18:14:17
【问题描述】:
谁能帮我写重写器,在这些条件下重定向 httphttps(返回和强制取决于输入的 URL):
1) http://www.mydomain.com , http://www.mydomain.com/?p=home , http://www.mydomain.com/?p=home1 , http://www.mydomain.com/?qqq=home 始终是 http,即使键入的是 https 而不是 http。
2) 所有其余页面始终为 https,即使输入的是 http 而不是 https。
下面的代码将除http://www.mydomain.com 之外的所有url(并保留参数)重定向到https。
#redirects http to https if there are parameters
RewriteCond %{HTTPS} off
RewriteCond %{QUERY_STRING} !^$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
我尝试在上面的代码之后添加下面的代码以将 https 也重定向到 http(如果没有参数),以便所有页面始终为 https,除了 www.mydomain.com,但我有没运气。我也错过了 ?p=home, ?p=home1, ?qqq=home - 我不知道如何添加它们。
RewriteCond %{HTTP} off
RewriteCond %{QUERY_STRING} ^$
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
【问题讨论】:
标签: http .htaccess mod-rewrite redirect https