2016-05-09 9 views
0

monsite.frのSSL証明書のみを所有するサイトで作業しています。私はwwwを削除しようとしています。 https://monsite.frにリダイレクトします。 ユーザタイプがwww.monsite.frの場合、リダイレクトは機能しません。https://monsite.frにリダイレクトされず、https://www.monsite.frにリダイレクトされ、認証エラーNET::ERR_CERT_COMMON_NAME_INVALIDが返されます。Apache VirtualHost:ストリップwww。 force https

<IfVersion <2.3> 
    NameVirtualHost *:80 
    NameVirtualHost *:443 
</IfVersion> 

<VirtualHost *:80> 
    ServerName monsite.fr 
    Redirect/https://monsite.fr/ 

    #RewriteEngine On 
    #RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
    #RewriteRule ^(.*)$ https://%1$1 [R=permanent,L] 
</VirtualHost> 

<VirtualHost *:80> 
    ServerName www.monsite.fr 
    Redirect/https://monsite.fr/ 
</VirtualHost> 

<VirtualHost *:443> 
    ServerName monsite.fr 
    ServerAlias www.monsite.fr 

    #RewriteEngine On 
    #RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
    #RewriteRule ^(.*)$ https://%1$1 [R=permanent,L] 

    RewriteEngine On 
    RewriteCond %{HTTPS} =on 
    RewriteCond %{HTTP_HOST} ^www\. 
    RewriteRule ^(.*)$ https://monsite.fr/$1 [R,QSA,L] 

    DocumentRoot "/opt/monsite.fr/htdocs" 
</VirtualHost> 

https://monsite.frwww.monsite.frをリダイレクトするためのソリューションがあります:

これはmysite.confファイルの内容は?次のように

答えて

1

は、あなたのバーチャルホストの設定を変更します。

<VirtualHost *:80> 
     ServerName www.monsite.fr 
     ServerAlias monsite.fr 
     RedirectMatch ^/(.*)$ https://monsite.fr/$1 
    </VirtualHost> 

    <VirtualHost *:443> 
     ServerName www.monsite.fr 
     RedirectMatch ^/(.*)$ https://monsite.fr/$1 
    </VirtualHost> 

    <VirtualHost *:443> 
     ServerName monsite.fr 
     SSLEngine On 
     SSLCertificateFile /path_to_cert/server.crt 
     SSLCertificateKeyFile /path_to_key/server.key 
     DocumentRoot "/opt/monsite.fr/htdocs" 
    </VirtualHost> 

最初の仮想ホストブロックがhttps://monsite.frhttp://www.monsite.frからのすべての要求をリダイレクトします。また、第二の仮想ホストブロックがhttps://www.monsite.frからhttps://monsite.frへのすべての要求をリダイレクトしますhttps://monsite.fr

http://monsite.frからのすべての要求をリダイレクトします。

第3の仮想ホストブロックは、https://monsite.frのコンテンツを提供します。上記の設定を編集して、SSL証明書には/path_to_cert/server.crt、秘密鍵には/path_to_key/server.keyという正しいパスを追加してください。

関連する問題