mod rewrite - Apache VirtualHost: strip www. and force https -
i working on site owns ssl cert monsite.fr. trying remove www. , redirect https://monsite.fr. redirection doesn't work if user type www.monsite.fr, not redirected https://monsite.fr https://www.monsite.fr , certification error net::err_cert_common_name_invalid.
this content of mysite.conf file:
<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> is there solution redirect www.monsite.fr https://monsite.fr ?
modify vhost configuration follows:
<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> the first virtual host block redirect requests http://www.monsite.fr https://monsite.fr. redirect requests http://monsite.fr https://monsite.fr
the second virtual host block redirect requests https://www.monsite.fr https://monsite.fr.
the third virtual host block serve content https://monsite.fr. make sure edit above mentioned configuration , add correct path /path_to_cert/server.crt ssl certificate , /path_to_key/server.key private key.
Comments
Post a Comment