By Anibal Ardid
Hi, I have installed https with letsencrypt, but the https url is redirecting to http
how can I fix it ?
I have both .conf files, and .htaccess
ssl.conf:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName xxxxx.com
ServerAlias www.xxxx.com
DocumentRoot /var/www/xxxx.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/xxxx.com/public_html">
AllowOverride All
Options Indexes FollowSymLinks MultiViews
</Directory>
SSLCertificateFile /etc/letsencrypt/live/xxxx.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/xxxx.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/xxxx.com/chain.pem
</VirtualHost>
</IfModule>
nossl.conf:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName xxxx.com
ServerAlias www.xxxx.com
DocumentRoot /var/www/xxxx.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/xxxx.com/public_html">
AllowOverride All
Options Indexes FollowSymLinks MultiViews
</Directory>
</VirtualHost>
.htaccess of my site:
<IfModule mod_rewrite.c>
#Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
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!
Hi!
I don’t see any rules that might cause an https->http redirect. What web app are you running on that domain name? Is it possible that it might be causing the redirect? Does it also happen in a different browser or in private/incognito mode?
Or, if you do not mind, please post the domain name so that I can see if it’s the same on my end.
Hello,
You can try with some of the following rules:
The following forces any http request to be rewritten using https. For example, the following code forces a request to http://example.com to load https://example.com. It also forces directly linked resources (images, css, etc.) to use https:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
The below code when added to an .htaccess file will automatically redirect any traffic destined for http: to https:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Let me know how it goes.
Regards, Alex
Try the following config. Restart your server without fail .It works on Centos 7
nossl.conf
<VirtualHost *:80>
ServerName yoursite.com
ServerAlias www.yoursite.com
DocumentRoot /var/www/yoursite.com/public_html
<Directory "/var/www/ranmarc.com/public_html">
Options FollowSymLinks MultiViews
# AllowOverride controls what directives may be placed in .htaccess files.
AllowOverride All
# Controls who can get stuff from this server file
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/www/yoursite.com/error.log
CustomLog /var/www/yoursite.com/requests.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =yoursite.com [OR]
RewriteCond %{SERVER_NAME} =www.yoursite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName yoursite.com
ServerAlias www.yoursite.com
DocumentRoot /var/www/yoursite.com/public_html
<Directory "/var/www/yoursite.com/public_html">
Options FollowSymLinks MultiViews
# AllowOverride controls what directives may be placed in .htaccess files.
AllowOverride All
# Controls who can get stuff from this server file
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/www/yoursite.com/error.log
CustomLog /var/www/yoursite.com/requests.log combined
SSLCertificateFile /etc/letsencrypt/live/yoursite.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yoursite.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/yoursite.com/chain.pem
</VirtualHost>
</IfModule>
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.