Question

Http to Https redirection not working on Wordpress Digital Ocean Droplet One Click

Hi. I have the droplet with wordress.

wordpress-ubuntu-s-1vcpu-1gb-amd-sfo3-01 Apache, Ubuntu 20

I followed this instruction https://certbot.eff.org/instructions

Now it’s working. https://mydomain.com/ - ok

But http://mydomain.com/ doesn’t work =(

The redirect goes here https://root/:

error DNS_PROBE_FINISHED_NXDOMAIN

The .htaccess in /var/www/html:

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

</IfModule>

Help me please


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.

SOLVED.

find the two files: 000-default.conf 000-default-le-ssl.conf

in the folders: /etc/apache2/sites-enabled/ /etc/apache2/sites-available/

  1. Replace YOURDOMAIN to your domain =)

  2. Remove the lines with the wrong URL that you see in the browser. Like this

RewriteCond %{SERVER_NAME} =www.root [OR]

000-default-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        
        ServerName YOURDOMAIN
        ServerAlias www.YOURDOMAIN
        
        DocumentRoot /var/www/html

        <Directory /var/www/html/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

ServerAlias crunchdubai.com
SSLCertificateFile /etc/letsencrypt/live/crunchdubai.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/crunchdubai.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

000-default.conf

UseCanonicalName On

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        
        ServerName YOURDOMAIN
        ServerAlias www.YOURDOMAIN
        
        DocumentRoot /var/www/html

        <Directory /var/www/html/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.crunchdubai.com [OR]
RewriteCond %{SERVER_NAME} =crunchdubai.com [OR]

RewriteCond %{SERVER_NAME} =www.root [OR] // DELETE THIS LINE
RewriteCond %{SERVER_NAME} =root [OR] // DELETE THIS LINE


RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

restart Apache2 by command line or reset the server by “Power cycle”

Clear your browser cache

Enjoy

BIG THANX KFSys & Bobby Iliev

KFSys
Site Moderator
Site Moderator badge
December 14, 2022

Hey @smallaquacrab,

The .htaccess file you’ve shown is perfectly fine. The issue is coming from your Apache virtual host and that is only for the HTTP part. Check your /etc/apache2/sites-available for the said vhost and if you need some help you can post it.

Most probably there is a redirect there which needs to be removed.

Bobby Iliev
Site Moderator
Site Moderator badge
December 4, 2022

Hi there,

Your .htaccess file looks good. The problem is most likely coming from the Apache Virtual Host for your website.

You can find the Apache virtual host in the following directory:

/etc/apache2/sites-enabled

In there there will be a file for your HTTP and HTTPS versions of your website. You need to find the one for the HTTP version of your website and update the redirect in there so that it does not go to https://root/ but to https://yourdomain.com.

Feel free to share the content of the file here and I can advise you which lines you need to change!

Best,

Bobby

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