-1

First and foremost, thank you for your time with my question.

I am attempting to forward all traffic from http:// and https:// to "https://www.[domain].com/[etc]" I am currently able to force all "www." traffic to "https://www." using the setup in httpd.conf below:

<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://{%SERVER_NAME}%{REQUEST_URI}
</VirtualHost>

This setup is unfortunately inconsistent. If for instance I enter "https://[domain].com" into a browser address bar, it will not redirect. On some browsers, "http://[domain].com" will redirect to the non-www "https://[domain].com" as well.

Long story short, I am having trouble setting up a proper redirect from any domain prefix to "https://www" on an Amazon EC2 Instance within the httpd.conf file. If you can help me out here, I'd really appreciate it. Thank you again for your time.

Edit: There is another Q&A that goes over general rewrite rules, however there are some specific rules for the Amazon EC2 (ELB) that are not covered in that answer. Frankly, I'm not sure if the Amazon EC2 specifics apply to my question, but the code I have (x-forwarded-proto) is specific for the ELB.

For what it's worth, I'm asking this question because all of my resources have been exhausted. If I found (or find) an answer somewhere else, I will happily update my question with information and a link.

Edit2: The following code redirects from [domain].com, http://[domain.com], and http://www.[domain].com to https://www.[domain].com. Unfortunately https://[domain].com still does not redirect.

<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://{%SERVER_NAME}%{REQUEST_URI}

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>

Is there a different VirtualHost I need to have set up for the https:// domain redirect?

  • After reading through this link, I do not believe the answer effectively covers my question, particularly for the Amazon EC2 server. I could be wrong, and I'll be really embarrassed if I'm wrong, but I don't see it. – Demir Oral Jul 18 '16 at 17:19
  • `Is there a different VirtualHost I need to have set up for the https:// domain redirect?` Yes, (aside from any other issues that your configuration _might_ have) you need `` – Colt Jul 18 '16 at 20:04
  • Hi @Colt, thanks for your input. Would this be appropriate to open a listener? Listen 80 Listen 443 stuff – Demir Oral Jul 18 '16 at 21:17
  • The Listen directives are generally in main conf files (or an imported conf such as ports.conf). The most important part of the 443 virtual host, however, will be that it is SSL "capable" or it will _not_ be able to do _anything_, including rewrite, to the https traffic – Colt Jul 18 '16 at 21:48

1 Answers1

-1

This will enable the Rewrite capabilities:

RewriteEngine On

This checks to make sure the connection is not already HTTPS:

RewriteCond %{HTTPS} !=on

This rule will redirect users from their original location, to the same:

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

The leading slash is made optional so that this will work either in httpd.conf location but using HTTPS.

Paul
  • 2,755
  • 6
  • 24
  • 35