PROBLEM:
I have an SSL certificate from a vendor installed and I want all visitors who come via HTTP to be redirected to HTTPS website-wide, but no matter what I try, I cannot figure out how to do it here. After more than a day trying many suggestions from numerous forums and Digital Ocean’s tutorials, I still cannot get it and I am running out of options. I tried:
a) The permanent redirect in the port 80 Host configuration file(mysite.com.conf): “Redirect permanent / https://mysite.com/." That always results in a redirect loop.
b) I have tried implementing numerous suggestions from multiple forums and blogs as to rewriting rules in mysite.com.conf. Again, I either get the loop, or no redirecting to HTTPS.
c) I tried editing the .httaccess file. No redirecting to HTTPS.
Can anyone provide a substantive guide as to how to trouble shoot this?
My configuration is underneath the line below.THANKS!
LAMP
I have two virtual hosts, one for port 80 ( etc/apache2/sites-available/mysite.com.conf) and another for port 443( /sites-available/mysite-sll.conf).
The port 80 host’s configuration is as follows:
ServerName mysite.com ServerAlias www.mysite.com DocumentRoot /var/www/mysite/public <Directory /var/www/mysite/public>
Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </Directory>
The port 443 host’s configuration is as follows:
<IfModule mod_ssl.c> <VirtualHost default:443>
ServerName mysite.com ServerAlias www.mysite.com DocumentRoot /var/www/mysite/public SSLEngine on SSLCertificateFile /etc/ssl/private/mysite_com.crt SSLCertificateKeyFile /etc/ssl/private/mysite.com.key SSLCertificateChainFile /etc/ssl/private/client.crt
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Click below to sign up and get $100 of credit to try our products over 60 days!
In your port 80 virtualhost I would recommend replacing:
with:
In order for this to work you will need to ensure that you have the rewrite module active in apache:
and once you have made the changes you will want to restart apache for them to take effect:
@ryanpq , thanks it worked
@ryanpq - Worked like a charm! So easy but for a novice this is a wealth of value! Thank you!!!
Thanks a lot, ryanpq. I found the problem, which was not related to the Virtual Hosts settings. The culprit was one of my SSL settings at CloudFlair, which kept redirecting users who tried to access port 443 back to port 80, hence the loop.