2016-05-17 5 views
0

に一致した場合、私は、ドメインマッチとも非WWW場合は、すべてのドメインのためのWWWにhttpsに非HTTPSをリダイレクトします。htaccessの条件付きリダイレクトドメインは

ここは、www以外のものをhttpsバージョンのwwwにリダイレクトしない以外は動作するマイコードです。

注:URLにwwwを追加した場合、広告はwww 2xとなるため、非wwwとwwwバージョンのルールが分かれています。

RewriteEngine On 

#all non-www to www (without HTTPS) 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

#non-https to https if these 2 domains matched - and since there is already www don't add it. 
RewriteCond %{HTTP_HOST} ^www\.domainA\.com [NC,OR] 
RewriteCond %{HTTP_HOST} ^www\.domainB\.com [NC] 
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

#non-https to https if these 2 domains matched - and also www 
RewriteCond %{HTTP_HOST} ^domainA\.com [NC,OR] 
RewriteCond %{HTTP_HOST} ^domainB\.com [NC] 
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !index 
RewriteRule (.*)$ index.html 
+0

何が問題なのですか? – anubhava

+0

@anubhavaもし私がhttps:domainA.comにアクセスすると、それにwwwが追加されません。 –

答えて

0

これを追加してみてください。 https://

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ 
RewriteCond %{HTTPS}s ^on(s)| 
RewriteRule^http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
0

コードを使用している任意のドメインに送信できます。問題は、ホストにwwwが設定されていないことでした。