Hi,
I want to redirect http://domain.com to https://www.domain.com?
I succeeded in redirecting http to https like this (in default-ssl.conf file):
<pre> <VirtualHost domain.com:80> RewriteEngine on ReWriteCond %{SERVER_PORT} !^443$ RewriteRule ^/?(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>
<VirtualHost default:443> RewriteEngine on ServerAdmin webmaster@localhos ServerName domain.com:443 ServerAlias www.domain.com DocumentRoot /var/www/html </pre>
this works fine until I type my domain without www, then I get the error message “this site is untrusted, the certificate is only valid to www.domain.com”
My environment:
will appreciate you help thanks,
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
note: <br>the default-ssl.conf is: <br> <br>“<VirtualHost DOMAIN.COM:80>” <br>RewriteEngine on <br>ReWriteCond %{SERVER_PORT} !^443$ <br>RewriteRule ^/?(.*) https://%{HTTP_HOST}/$1 [NC,R,L] <br>“</VirtualHost>” <br> <br>“<VirtualHost DEFAULT:443>” <br>RewriteEngine on <br>ServerAdmin webmaster@localhost <br>ServerName domain.com:443 <br>ServerAlias www.domain.com <br>DocumentRoot /var/www/html <br>“</VirtualHost>”
sorry the post does not accept programatic brackets. so first block of code is for <br>VirtualHost domian.com:80 <br> <br>the second block is for <br>VirtualHost default:443
I found the solution, for the people who suffered as me in finding a solution… here is the answer: <br> <br>VirtualHost domain.com:80 <br> <br> RewriteEngine on <br> ReWriteCond %{SERVER_PORT} !^443$ <br> RewriteRule ^/?(.*) https://%{HTTP_HOST}/$1 [NC,R,L] <br> <br>VirtualHost default:443 <br> <br> ServerAdmin webmaster@localhost <br> ServerName domain.com:443 <br> ServerAlias www.domain.com <br> DocumentRoot /var/www/html <br> RewriteEngine on <br> RewriteCond %{HTTP_HOST} !^(www.)?(.+) <br> RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L] <br> <br>Enjoy! <br>
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.