How to purge server redirects?

Hello,

I have nginx. It had since years this rewrite:

server {
        listen 80;
        server_name www.anahatatantra.com anahatatantra.com;
        root /var/www/anahatatantra.com;

        rewrite  ^/(.*)$  https://anahatatantra.com/$1 permanent;
}

And it was making a double redirect if a user entered non-https and non-www at the same time:

http://anahatatantra.com/pl/kontakt/
**301 Moved Permanently**
https://anahatatantra.com/pl/kontakt/
**301 Moved Permanently**
https://www.anahatatantra.com/pl/kontakt/
**200 OK**

Yesterday, in order to avoid a double redirect I changed it to:

server {
        listen 80;
        server_name www.anahatatantra.com anahatatantra.com;
        root /var/www/anahatatantra.com;

        return 301 https://www.anahatatantra.com$request_uri;
}

and then of course restarted nginx purged the cache in CF.

Today there are still double redirects. I tried different subpages. Everywhere the same situation.
Please note that there are no caching plugins in the blog. Also I tried many online tools to test the redirects.

It really seems that the redirects are somehow cached in CF.

I’ve even tried to temporarily change the redirect from 301 to 302 and always 301 is being detected.

Can anyone please help me out?

If you have “Always use HTTPS” enabled on Cloudflare, the http->https redirect will be done there first.
https://cf.sjr.org.uk/tools/check?bfc355b4f2ae4c4bbccdc6c7ed01fcc4#connection-server

1 Like

Wonderful! Thank you <3
It works now fine and it loads faster.

Hang on, is this your only configuration? Is your server not listening on port 443? You’ll still have an insecure site.

No now, it would work if that was the only configuration.

I have a separate virtualhost that handles https 443 ssl requests and a 443 ssl that handles non-www requests that redirects to www.
The problem was only the virtualhost listening to port 80.

Never mind then :slight_smile: and @sjr’s response is of course spot on

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.