2016-05-09 4 views
2

は(あなたがアドレスバーに直接入力した場合)https://example.com にリダイレクトすることですので、.htaccessの自動リダイレクト私がしようと何

http://www.example.com -> https://example.com 
https://www.example.com -> https://example.com 
example.com -> https://example.com 
www.example.com -> https://example.com 

私はすでに試した(そして他の方法の他のロット):

RewriteCond %{SERVER_PORT} ^80$ 
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] 
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L] 

RewriteCond %{SERVER_PORT} ^443$ 
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] 
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L] 

ので

http://www.example.com 
https://www.example.com 
www.example.com 

は、すべてのにリダイレクトされます

しかしexample.comは、私はそれをacomplishするにはどうすればよいhttps://example.com

に自動的にリダイレクトされませんか?

答えて

0

あなたは両方の要求をWWWまたはhttp照合し、私は@starkeen s'の方法がうまくいくと思います...しかし、あなたがCloudFlareのを使用しているいないときhttps://non-www

RewriteCond %{HTTPS} off [OR] 
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] 
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L] 
+0

残念ながら 'ます。https:' ERR_TOO_MANY_REDIRECTS'は – bwh

+0

:// example.com/'はエラーを生成します。コード – starkeen

+0

をクリアしてみてください@bwh無限ループ – bwh

0

にリダイレクトするためにOR条件を使用することができます!! Cloudflareを使用している人のためのソリューション:

Force HTTPS By default CloudFlare HTTPS doesn't force all the traffic to HTTPS. To force HTTPS do the following:

Go to your websites Click on the gear icon and select "Page rules" Enter your website in the URL pattern input Toggle the "Always use HTTPS" switch Click on "Add rule" at the bottom By doing this all the traffic of your website will use HTTPS. When someone access your website using HTTP, CloudFlare will redirect those request to HTTPS.

関連する問題