Question

How to disable Letsencrypt redirect all requests to secure HTTPS access

I did the Letsencrypt installation and it works great. I choose the option to redirect all requests to secure HTTPS access.

I saw those lines added by Letsencrypt in /etc/apache2/sites-available/000-default.conf

        RewriteEngine on
        RewriteCond %{SERVER_NAME} =evolutionary.co
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

Now I want to disable this feature and to have a part of website without ssl. So I commented those lines and reloaded Apache but the redirection is still active: http://mydomain.com still redirect to https://mydomain.com

How can I fix that?


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Accepted Answer

Yes you are right it was a cache problem because of header time config.

Found the solution here : https://community.letsencrypt.org/t/always-redirect-to-https/10838/2

Seems like you added the HSTS header to your apache conf. This directive tells the browser visiting your site that for the max age configured in the directive, the browser should access your site always using https. So the “problem” is in your browser right now.

In your apache conf you should have/had something like this:

Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"

3.- Recover all the apache and letsencrypt files that you removed, edit apache conf and change the header directive using max-age=0, something like this: Header always set Strict-Transport-Security “max-age=0; includeSubdomains; preload”

Reload or restart apache and visit again your site, once visited the browser will ignore the htst header and you could access your site using only http.

I modified this directive using max-age=0 and it worked right away…

KFSys
Site Moderator
Site Moderator badge
February 7, 2024

Hey all,

For anyone that stumbles upon this.

The redirect was indeed happening because of the following rules

        RewriteEngine on
        RewriteCond %{SERVER_NAME} =evolutionary.co
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

Usually, such a rule should be added in the .htaccess file of the website rather than the configuraiton file but both do work.

If you have added the rule in your configuration file, commenting out the lines would require a systemctl restart of Apache while if you add it to your .htaccess file there wouldn’t be a need for one.

Please post your /etc/apache2/sites-available/000-default.conf file and .htaccess file if you have one.

One more thing to note is browsers will cache redirects. You may want to test it using incognito mode.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel