【发布时间】:2017-03-14 17:38:04
【问题描述】:
我的 htaccess 文件中有以下规则:
RewriteRule ^(.*)$ https://example.com/?http://%{HTTP_HOST}%{REQUEST_URI}?%{QUERY_STRING} [NE,R=302,L]
但我想根据使用的协议(HTTP 或 HTTPS)重定向用户。我试过这个:
RewriteRule ^(.*)$ https://example.com/?%{SERVER_PROTOCOL}://%{HTTP_HOST}%{REQUEST_URI}?%{QUERY_STRING} [NE,R=302,L]
但用户被重定向到“https://example.com/?HTTP/1.1://example.com/anything?anything”
我不想将 RewriteCond 用于这样的简单任务,是否有任何变量可以用于此,我的意思是,返回 http 或 https?我在这里查了http://httpd.apache.org/docs/current/mod/mod_rewrite.html,但不确定是否有。
【问题讨论】:
-
你的意思是 %{REQUEST_SCHEME} 吗?
-
是的 :) 请发表我会批准的答案,谢谢!
标签: apache .htaccess mod-rewrite