Hello everyone.
I have some strange issue related to the redirect loop appearing.
For example, my website is https://www.test.org/ in the website general setting I have the same address:https://www.test.org/ in digitalocean domain setting I add that:
test.org is posting to IP wwww.test.org is posting to the same IP
also in this file 000-default.conf (folder site enabled) I have those lines:
RewriteEngine on RewriteCond %{SERVER_NAME} =www.test.org [OR] RewriteCond %{SERVER_NAME} =test.org RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
and in the .httaces file, I have nothing.
**But when I enter to the browser this one http://www.test.org/ I have those redirect chains: **
http://www.test.org/ 301 redirect to https://test.org/ 301 redirect to https://www.test.org/
Somebody could help how to avoid the second unnecessary chain element in order to get the redirect from http://www.test.org/ directly here: https://www.test.org/ and from http://test.org/ also directly here https://www.test.org/
Many thanks
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!
Accepted Answer
Hello,
I believe that this might be an issue with your web application itself. You need to make sure that your application URL is setup correctly.
For example if you are using Wordpress you need to make sure that you update your Site and Home URLs as https://www.test.com
Or if you are using Laravel for example make sure to set the correct app URL in your .env file.
Let me know how it goes! Bobby
Yesterday I saw that left small issue - from this url https://test.org/ don`t work the redirect here: https://www.test.org/
I use your 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]
instead my old one:
RewriteEngine on
RewriteCond %{SERVERNAME} =www.test.org [OR]
RewriteCond %{SERVERNAME} =test.org
RewriteRule ^ https://%{SERVERNAME}%{REQUESTURI} [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/ - don`t redirect here https://www.test.org/
https://www.test.org/ - is ok
So as you see this url: https://test.org/ don`t 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 redirect from the / - main page to another website.
And interesting thing - when I delete this redirect via redirection plugin all seems that works well and all redirection scenaria works well, but when I use the redirection plugin only this one scenario:
https://test.org/ - don`t redirect here https://www.test.org/
don`t work.
Tell, please should we customize the code that you provided or the problem in this “Redirection” plugin and could you help with this issue?
Many thanks.
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.