Question

https is redirecting to http , how can I do the reverse ?

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>

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

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>

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.