Author Topic: Definitive answer: HTTP to HTTPS www  (Read 6550 times)

0 Members and 1 Guest are viewing this topic.

Definitive answer: HTTP to HTTPS www
« on: August 10, 2018, 01:11:19 PM »
I have been struggling with this for days but can't get this to work in all situations.

What is the proper way (per domian) to direct all traffic to https://www.domain.tld/:

http://domain.tld-> https://www.domain.tld/
http://www.domain.tld-> https://www.domain.tld/
https://domain.tld-> https://www.domain.tld/

I am using Apache & Varnish Cache & Nginx Reverse Proxy and AutoSSL. I have tried rewrites and redirects in .htaccess and in vhosts configs but I have been unsuccessful.

I know you can edit the vhost templates and I also see that you can have per domain, custom config files but what is the proper code and way of doing this so the configurations are not lost when CWP rebuilds the vhosts?

Help... I'm starting to hemorrhage!
« Last Edit: August 10, 2018, 01:13:01 PM by jeffshead »

Re: Definitive answer: HTTP to HTTPS www
« Reply #1 on: October 12, 2018, 04:55:27 PM »
Today (a little late) I modified vhost template by adding this:

<IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{HTTPS} off
      RewriteRule ^(.*)$ https://DOMAIN_REPLACE$1 [R=301,L]

This will redirect http requests to https.  You must have https cert of course.

Also VERY will have to delete this rewrite module every single time that you attempt to renew certs.  And then manually insert it after cert is renewed.  Easiest way to do this is to have two copies of your vhost config file.  One with the rewrite and one without the rewrite.  This will save you a ton of time if you numerous domains.  If you have only one then its just as easy to type it in each time.  ALTERNATIVELY you can comment out the rewrite with hash tags prior to cert renewal.

Re: Definitive answer: HTTP to HTTPS www
« Reply #2 on: October 12, 2018, 09:53:42 PM »
Thanks for the reply. I appreciate you taking the time :-)

I think you may have overlooked that I stated I'm using the NGINX reverse-proxy. I did figure out a way to make it work though.

I edited the NGINX vhosts templates so that I now have a 301 redirect from http to https and I added an additional server instance in the NGINX ssl vhost template so I now have a domain.tld and a www.domain.tld instance. The domain.tld server has a 301 redirect to www.domain.tld.

It works great!

Re: Definitive answer: HTTP to HTTPS www
« Reply #3 on: October 12, 2018, 11:30:13 PM »
What you just said is what I posted.

Re: Definitive answer: HTTP to HTTPS www
« Reply #4 on: October 13, 2018, 10:59:44 AM »
No, it's not  :) You posted an Apache redirect. I stated that I changed my NGINX config to redirect. Are you using the redirect you posted with Apache & Varnish Cache & Nginx Reverse Proxy?

I could not get any http-to-httpswww Apache redirects to work (flawlessly) behind the NGINX reverse-proxy including the one that you posted. Some would loop and some would cause server errors. I'm also behind a web server firewall appliance so maybe that has something to do with it. The NGINX redirects work flawlessly and I believe that's where the redirects should be done since incoming traffic hits NGINX before it gets to Apache.
« Last Edit: October 13, 2018, 11:04:28 AM by jeffshead »