ウェブサイトのリダイレクトはFirefoxでは断続的に機能しますが、IEではまったく機能しません[重複]
ウェブサイトのリダイレクトでエラーを数回試した後、ウェブサイトのリダイレクトを実行できましたが、Firefoxでは断続的に機能しますが、IEではまったく機能しません。Firefoxですべてのキャッシュをクリアして再試行することができ、それは機能しますが、奇妙なことに、その後は機能しません。その時点で、どのファイルにも変更を加えていないことを確認しました。誰かが以前にこれに何か考えや直面したことがありますか?私は2分ほど幸せだったのに、私のWebサイトが最終的にリダイレクトされて、それが再びリダイレクトされなかったことが判明したことをとても嬉しく思いました。:((http://example.comと入力すると、リダイレクトする必要があります。https ://www.example.comにリダイレクトされます。 以下は、.htaccessファイルでのリダイレクトです。
RewriteEngine On
#Options +FollowSymLinks
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} ^example\.com$[OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]
以下は私のログです:
init rewrite engine with requested uri /
pass through /
[perdir D:/wamp64/www/example/] strip per-dir prefix: D:/wamp64/www/example/ ->
[perdir D:/wamp64/www/example/] applying pattern '.*' to uri ''
[perdir D:/wamp64/www/example/] RewriteCond: input='off' pattern='!on' => matched
[perdir D:/wamp64/www/example/] RewriteCond: input='www.example.com' pattern='^www\\.example\\.com$' => matched
[perdir D:/wamp64/www/example/] rewrite '' -> 'https://www.example.com/'
[perdir D:/wamp64/www/example/] explicitly forcing redirect with https://www.example.com/
[perdir D:/wamp64/www/example/] escaping https://www.example.com/ for redirect
[perdir D:/wamp64/www/example/] redirect to https://www.example.com/ [REDIRECT/301]
また、VPNからログアウトしたときにのみWebサイトがリダイレクトされることもわかりました(リダイレクトのために行った情報を修正または取得するためにサーバーに接続できるように、VPNを使用する必要があります)
以下は、.htaccessファイルに追加したアイテムです。
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{HTTP_HOST] ^www\.example\.com$
RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]
以下は私のhttpd-vhosts.confです:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "d:/wamp64/www/example"
<Directory "d:/wamp64/www/example/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
Allow from all
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
</Directory>
</VirtualHost>
私のSSL証明書はhttpd-ssl.confで構成されているので、httpd-vhosts.confをVirtualHostとして指定します*:80以下は私のhttpd-vhosts.confです。
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "d:/wamp64/www/example"
<Directory "d:/wamp64/www/example/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
Allow from all
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
</Directory>
</VirtualHost>
更新
以下は、[OR]を追加して.htaccessで更新したものです。
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]
そして、以下は私が得たログです:
strip per-dir prefix: D:/wamp64/www/example/ ->
applying pattern '.*' to uri ''
RewriteCond: input='off' pattern='!on' => matched
rewrite '' -> 'https://www.example.com/'
explicitly forcing redirect with https://www.example.com/
escaping https://www.example.com/ for redirect
redirect to https://www.example.com/ [REDIRECT/301]
ブラウザで再試行しましたが、リダイレクトされませんでした。また、Firefoxでデバッグしようとしています。取得したホストはexample.comです。
これは私が[OR]を削除することによって得たものです
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]
ログ:
RewriteCond: input='off' pattern='!on' => matched
RewriteCond: input='www.example.com' pattern='^example\\.com$' => not-matched
私のリダイレクトが機能していることを教えてください。私はこれで何ヶ月も働いていて、今はアイデアがなくなっています(私の愚かな間違いが原因ではないことを願っています...祈っています!)。よろしくお願いします!
回答
私はあなたが実際にこの状態を望んでいないと信じています:
RewriteCond %{HTTP_HOST} ^www\.example\.com$
これはバージョンにも.htaccess
適用されるものであるため、それ自体への無限のリダイレクトループが発生するためですhttps://www
。
RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]
スペースが足りない文字だと思います。これを変更してください:
RewriteCond %{HTTP_HOST} ^example\.com$[OR]
これに:
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
ログファイルのエントリは、http://www.example.comがhttps://www.example.com/に正常に書き換えられたことを証明しました。彼らはhttp://example.comについて何も証明しませんでした。スペース文字を追加すると、後者が修正されます。
代わりにmod_rewrite
、仮想ホストの定義で次のようなものを使用する必要があります。
ServerName www.example.com
ServerAlias example.com
Redirect permanent / https://www.example.com/
Apachehttpdドキュメントによると 。
mod_rewriteは、他の選択肢が必要な場合の最後の手段と見なす必要があります。より単純な代替手段がある場合にそれを使用すると、混乱し、壊れやすく、保守が難しい構成になります。