2017-07-05 12 views
0

私はHTTPSにHTTPからすべてのトラフィックをリダイレクトしたいのですが、特定のURLは/ oldsiteと異なっている場合にのみ、(だけサブドメインSUB1とSUB2で)HTTPSへのリダイレクトだけで特定のドメイン/サブドメインおよび特定のURL

例えば:

http://example.com/any/thing --> redirects to --> https://example.com/any/thing 

http://sub1.example.com/any/thing --> redirects to --> https://sub1.example.com/any/thing 

しかし

http://example.com/oldsite/any/thing 

http://sub1.example.com/oldsite/any/thing -> do not cause this redirect 

私が試した:

RewriteEngine on 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(?:(sub1|sub2)\.)?example\.com 
RewriteCond %{REQUEST_URI} !^/oldsite [NC] 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

ありがとうございました。

UPDATE:HTTPSがオフのときに、あなたのルールを持っているし、代わりにREQUEST_URITHE_REQUEST変数を使用してください

RewriteCond %{THE_REQUEST} !/oldsite [NC] 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301, NE] 

答えて

0

:またとして最後の2行をテストし

RewriteCond %{HTTPS} off 
RewriteCond %{THE_REQUEST} !/oldsite [NC] 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 
+0

ありがとうございました...しかし、うまくいきませんでした...まだHTTPSにリダイレクトされています...どんなアイデアですか? 私はhttp://example.com/oldsite/a/bにアクセスしたばかりで、HTTPSバージョン – Pipe

+0

にリダイレクトされます。これが.htaccessの最初のルールであることを確認し、ブラウザのキャッシュを完全にクリアするか、コマンドからテストしてください'' curl''または '' wget'' – anubhava

関連する問題