简体   繁体   中英

Redirect https://example.com/ to https://www.example.com/ without changing httpd.conf

i bought a normal ssl (DV ssl) for my site www.example.com i created ssl on cpanel with no problem. so i added these lines in .htaccess and my website works to https very nice.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

ok here is my problem : this ssl works just for https://www.example.com (bought for just 1 address) so if every body type in browser https://example.com would get certificate error! i googled so much and find that i must create a virtualhost in httpd.conf to bypass certificate error. something like this code:

NameVirtualHost *:443
<VirtualHost *:443>
  ServerName example.com
  SSLCertificateFile /etc/ssl/apache2/server.crt
  SSLCertificateKeyFile /etc/ssl/apache2/server.key
  SSLEngine on
  RewriteEngine on
  RewriteRule ^/(.*)  https://www.example.com%{REQUEST_URI}      [L,R]
</VirtualHost>

but i can't change in httpd.conf because my site works on a shared hosting. so i phoned to hosting admin and ask him to create a virtualhost for me but no success!! how could i solve this problem? I would appreciate to anyone solve it.

If your certificate is for www.example.com and not for example.com you will always get a certificate warning when trying to access https://example.com because the hostname in the URL does not match the subject(s) of the certificate.

This is simply how certificate validation works and there is no change to httpd.conf, no redirection, no DNS CNAME, no tricks, no whatever which will help you solve this issue. Your only choice is to have a certificate which also matches example.com and there are several CA which offer you free certificates for this case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM