/ /すべてのサブドメインをhttpsではなくhttpにリダイレクトする方法-php、apache、.htaccess、mod-rewrite、redirect

https - php、apache、.htaccess、mod-rewrite、redirectの代わりにすべてのサブドメインをhttpにリダイレクトする方法

使用しているhtaccessファイルには次のものが含まれています

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don"t put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

このコードは、からURLをリダイレクトするのに役立ちます example.comから https://www.example.com

問題は、サブドメインをにリダイレクトすることです https://www.sub.example.com

サブドメインのみをリダイレクトしたい http://www.subdomain.example.com

回答:

回答№1は2

あなたは、 RewriteCondhttp->https メインドメインのみに制限するルール:

RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [NC]
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don"t put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.

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