私は次のような構成を持っているApacheの上の仮想ホストを持っている:HTTP特定の仮想ホスト用のApacheでHTTPSへ
<VirtualHost *:80>
DocumentRoot "/home/doe/www/factory/public"
<Directory "/home/doe/www/factory/public">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
ServerName doe.example.com
ServerAlias qa.dev
ServerAlias doe202.ddns.net
ErrorLog "/home/doe/logs/doe.log"
CustomLog "/home/doe/logs/aq-access.log" common
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/home/doe/www/factory/public"
<Directory "/home/doe/www/factory/public">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
ServerName doe.example.com
ServerAlias qa.dev
ServerAlias doe202.dddns.net
ErrorLog "/home/doe/logs/doe.log"
CustomLog "/home/doe/logs/aq-access.log" common
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/doe.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/doe.exmple.com/privkey.pem
</VirtualHost>
私は何を達成するために必要なのであるだけhttp://doe.example.com
もちろんのhttps://doe.example.com
にをリダイレクトします任意のURIを添付します。
私はその質問のthis answerを探すために試してみました:http to https apache redirectionが、それはHTTPSにすべてホストをリダイレクトします。
また、ポート80仮想ホストのserverName
ディレクティブを変更しようとしましたが、これによりhttp
を使用するユーザーがアクセスできなくなります。それが要求されるように、他のエイリアスがそのプロトコルを維持する一方で、このようにして
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^doe\.example\.com$ [NC]
RewriteRule ^(.*)$ https://doe.example.com/$1 [R=301,L]
# ... the rest of .htaccess
、唯一http://doe.example.com
はhttps://doe.example.com
にリダイレクトされます。
@ShingLamに書き換えを入れてください。 'VirtualHost *:80'に' serverAlias'が含まれていることに注意してください。すべてのホストはhttpsにリダイレクトされます。 – SaidbakR
他のすべてのサーバーエイリアスに対して、別のVirtualHost *; 80を設定しないで、servealias.whyを逃しました –