私は説明できない奇妙な動作に遭遇しました。 HTTP
リクエストをHTTPS
にリダイレクトする必要があります。私は次のコードを使用しました:RewriteRuleがファイルにマッピングする代わりにURLを変更する
RewriteEngine On
RewriteBase/
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# The query string in the rewrite is for testing purposes
RewriteRule (.*) /index.php?url=$1&%{REQUEST_URI}&http=%{HTTPS} [L]
これまでのところ、それは動作します。その後、私はHTTP
する単一のページを必要とするので、私はいくつかの書き換え条件を追加しました:さて、ここで何が起こっているのか
RewriteEngine On
RewriteBase/
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/not-https
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/not-https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php?url=$1&%{REQUEST_URI}&https=%{HTTPS} [L]
。何らかの理由で、ページにアクセスすると、/index.php?url=not-https&/not-https&https=off
にリダイレクトされます。
次に、リダイレクト/表示されたURLが続くGETリクエストのマップです。
GET: http://example.com/test
-> https://example.com/test with proper $_GET
GET: http://example.com/test.jpg
-> https://example.com/test.jpg with no $_GET (file exists)
GET: https://example.com/not-https
-> http://example.com/not-https
-> http://example.com/index.php?url=not-https&/not-https&https=off
私の質問は、なぜnot-https
表示されたURL(およびそのための、めちゃくちゃに自分のアプリケーションを)変更するんでしょうか?
ありがとう、それはすべてを解決しました。 'REQUEST_URI'は何とか変わっていたと私は推測しましたが、ドキュメントでは何も見つかりませんでした。さらに、 '.htaccess'ファイルをデバッグするのが非常に難しいと感じています... –