Question

301 Redirects Via 000-default.conf File and WordPress Redirection Plugin Issue

In the file 000-default.conf (folder site enabled) I have those lines:

# Added to mitigate CVE-2017-8295 vulnerability
UseCanonicalName On

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        
        ServerName test.org
        ServerAlias www.test.org
        
        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.test.org [OR]
RewriteCond %{SERVER_NAME} =test.org
RewriteRule ^ https://www.%1%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

For example, my website works on this address https://www.test.org/ and in the WordPress general settings I have the same address as the main website address: https://www.test.org/


Checking all redirection scenario, I saw that left small issue - from this URL https://test.org/ don`t work the redirect here: https://www.test.org/

I use this code:

RewriteEngine on RewriteCond %{SERVERNAME} =www.test.org [OR] RewriteCond %{SERVERNAME} =test.org RewriteRule ^ https://www.%1%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

So I checked all redirect scenario:

http://www.test.org/ - redirect here https://www.test.org/ http://test.org/ - redirect here https://www.test.org/ https://test.org/ - dont redirect here https://www.test.org/ https://www.test.org/ - is ok So as you see this URL: https://test.org/ dont redirect here: https://www.test.org/

Also actually I don`t know related it to this code or not, but also I use the special redirection plugin called “Redirection” for WordPress - I set-upped 301 redirects from the / - main page to absolutely another website.

And interesting thing - when I delete this redirect via redirection plugin all seems that works well and all redirection scenario works well, but when I use the redirection plugin only this one scenario:

https://test.org/ - don`t redirect here https://www.test.org/ - it directly begins to redirect to the another my website.

So when i using the redirection plugin from the / main page to another website all those redirects scenario works well except only one:

http://www.test.org/ - redirect here https://www.test.org/ and them to the another website

http://test.org/ - redirect here https://www.test.org/ and them to the another website

https://test.org/ - don`t redirect here https://www.test.org/ but directly redirect to another website

Tell please why it is happening and how to fix this issue?

Many thanks.

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 need to make sure that you have a VirtualHost for port 443 for your domain name.

The easiest way to do that is to install a Let’s Encrypt SSL certificate with CertBot which would automatically create the Vhost for you.

Hope that this helps! Bobby