I have a site example.com and setup a VirtualHost to redirect to https://www.example.com
When I go to http://example.com it works great, however https does not
How can I update my VirtualHost configuration to also direct https traffic?
<VirtualHost *:80>
ServerName example.com
Redirect permanent "/" "https://www.example.com"
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
Redirect permanent "/" "https://www.example.com"
</VirtualHost>
The top one works great and redirects as expected, but https://example.com does not
Confirmed in AWS that the instance allows all traffic on both ports 80 and 443
--update
This is hosted on an AWS EC2 instance, and the HTTPS certificate in question was issued via the AWS Certificate Manager. Per Shim's suggestion I looked at https://wiki.apache.org/httpd/NameBasedSSLVHosts but it requires me to export a certificate which AWS does not permit? Is there another way around this?
Related
What are all of the options to access only the www version of a URL e.g. https://www.example.com. The website in question has 150 pages and we need to ensure all traffic resolves to the www version.
Example: All options for this URL https://example.com to resolve to htts://www.example.com.
I’ve used an .htaccess redirect in the past, but the question is are there any other options and which is the best option
You have a tag of Apache, so assume you are running a reasonably recent version of Apache.
You can handle it with Apache Virtual Hosts. You will set up two files:
/etc/apache2/sites-available/www.example.com.conf
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/...
...
</VirtualHost>
/etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://www.example.com/
...
</VirtualHost>
In Apache you then need to enable both sites:
a2ensite www.example.com
a2ensite example.com
service apache2 reload
The first file sets up the main website: www.example.com, which directs Apache to load the DocumentRoot directory when it comes in.
The second file indicates that when example.com comes in on Port 80 - redirect to the https://www.example.com. Be sure to set the http or https depending on whether it is secure.
This kind of redirect causes the browser to change the address in the browser bar, which is the best redirect for what you are looking to do.
i have installed SSL.
and trying to redirect all HTTP request to HTTPS.
i came across this code snippet,
<VirtualHost *:80>
ServerName www.example.com
Redirect / https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
# ... SSL configuration goes here
</VirtualHost>
i will add it at httpd.conf (i am using apache from the wamp bundle)
my question is what should be there in "# ... SSL Configuration goes here"
i am using AWS certificate manager with Elastic Load Balancer
Thanks
You need the http to https redirection in apache configuration.
my question is what should be there in "# ... SSL Configuration goes
here"?
You don't need to add any SSL configuration since you can attach the SSL certificate to the ELB with AWS Certificates Manager, while terminating the SSL connection at the ELB.
You can use http to communicate from ELB to the EC2 instance.
If you use AWS ELB at ELB https will get terminated so just needs to add ssl certs to ELB
note from ELB to your EC2 will not be under https(i.e ssl encrypted)
if you use https Refer AWS documentation
refer
for non AWS accounts
<VirtualHost *:443>
ServerName example.com
DocumentRoot "/var/www/html/"
SSLEngine on
SSLCertificateFile "/etc/ssl/certs/example.crt"
SSLCertificateKeyFile "/etc/ssl/certs/example.key"
I know there are plenty of articles here talking about almost equal questions. However I couldn't fix it yet.
We have a normal wordpress domain
domain.com
I have two virtual hosts, one to http and another to https, from http virtual host I make a redirect to force the https always
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
Redirect permanent / https://domain.com
</VirtualHost>
then my https virtualhost is something like
<VirtualHost *:443>
ServerName domain.com
DocumentRoot /var/www/vhosts/puntdona.com/httpdocs
....
</VirtualHost>
Problem:
every time I enter into navigator something like
https://www.domain.com
navigator (Google,etc) complains about it because the certificate (chepeast one) just work to non www urls. I've tested lot of setups to try to redirect the
https://www.domain.com to http://domain.com
but didn't work.
I want to get that Apache redirects https://www -> to https:// (without www).
But I don't know how.
Thanks
You just can't redirect to mentioned url. To redirect you need to have different url.
For reference visit official apache docs -
http://httpd.apache.org/docs/2.4/rewrite/remapping.html
I installed SSL (stupidly) to encrypt the data being sent, the only trouble was my subdomain was redirecting to my main. I changed my default virtual host back to the original settings and also typed a2dismod ssl. Now when ever I type in www.domain.com it redirects to https://www.domain.com and then says SSL Connection Error.
I'm hoping to either get SSL working on the main+sub or just remove completely. Has anyone got any idea why it's redirecting to Https?
My VirtualHosts file is:
<VirtualHost *:80>
ServerName www.domain.com
DocumentRoot /var/www/folder
#SSLEngine on
#SSLCertificationFile /etc/apache2/ssl/apache.crt
#SSLCertificationKeyFile /etc/apache2/ssl/apache.key
</VirtualHost>
<VirtualHost *:80>
ServerName sub.domain.com
DocumentRoot /var/www/sub
#SSLEngine on
#SSLCertificationFile /etc/apache2/ssl/apache.crt
#SSLCertificationKeyFile /etc/apache2/ssl/apache.key
</VirtualHost>
Now if I un-comment the lines with # on and change *:80 to *:443 it redirects to the main site with SSL enabled...
You are enabling mod_ssl (with the "SSLEngine on" directive) on a HTTP Virtual Host on TCP/80. You need to set up different Virtual Hosts bound to the TCP/443 port, on only enable mod_ssl on these.
Otherwise, mod_ssl expect an HTTPS connection on port 80 and, seeing that your browser is speaking HTTP, tries to redirect the browser to https://www.domain.com.
Some context: I'm serving a website under the domains domain.com and alternate-domain.com. I would like to redirect all requests so that they:
use SSL (basically, redirect http -> https)
use the canonical hostname domain.com (e.g. remove the www prefix)
That's what I have at the top of my apache configuration:
<VirtualHost *:80>
Redirect permanent / https://domain.com/
</VirtualHost>
<VirtualHost *:433>
Redirect permanent / https://domain.com/
SSLEngine on
# SSL Certificate directives are here.
</VirtualHost>
And then later on I have the config for https://domain.com:
<VirtualHost *:443>
ServerName domain.com
# ...
</VirtualHost>
This works as expected when I access non-HTTPS pages:
http://www.domain.com redirects to https://domain.com
http://alternate-domain.com redirects to https://domain.com
However, it doesn't work when I access domains through HTTPS. What I mean by that is that the redirection doesn't happen.
Examples:
https://www.domain.com
https://alternate-domain.com
(Note: it's normal that certificate warnings occur as they don't match the domain for which I have the certificate. All the more reason for redirecting users.)
What am I doing wrong?
Ok, problem solved - I made a typical stupid mistake.
In the SSL default vhost, I listen on port 433. Should be 443of course.
Your config says that when someone enters a URL of https://groupstreamer.com/, the server should redirct them to https://groupstreamer.com/ - and you can't see the flaw here?
Lose the redirect in the 443 virtualhost. If you must use a front controller (which is wrong for so many reasons) then use the 404 handler.