2017-12-01 2 views
0

私は次のような構成を持っている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.comhttps://doe.example.comにリダイレクトされます。

+0

+0

@ShingLamに書き換えを入れてください。 'VirtualHost *:80'に' serverAlias'が含まれていることに注意してください。すべてのホストはhttpsにリダイレクトされます。 – SaidbakR

+0

他のすべてのサーバーエイリアスに対して、別のVirtualHost *; 80を設定しないで、servealias.whyを逃しました –

答えて

0

私が見つけた解決策は、次のようなwww to non www with hard redirectをリダイレクトするために使用ソリューションに依存します。

ちなみに、ウェブサイトはプロジェクトです。このプロジェクトのすべての.htaccess設定は上記の設定の隣にあります。

関連する問題