Changing 302 redirects to 301 sitewide

We’re having an issue with redirects on a website where the redirects from the non-www. URL to the www. URL are set to 302 rather than 301.

We recently migrated the website hosting when WordPress updated the default URL from www. to the non-www. version.

When we updated the domain back to the www. version which was the preference, there was mass 302’s (temporary redirects) that where put in place from the non-www. versions to www. versions.

We need to change these sitewide 302 redirects to 301s.

We have spoken to our hosting provider who have said that these redirects are set up within Cloudflare - “The redirection issue you’re experiencing originates from Cloudflare”.

The website in question is https://www.shuttersup.co.uk/ and it is hosted on a nginx server.

Cloudflare is redirecting (by 301) http://shuttersup.co.uk/ to https://shuttersup.co.uk/, likely because you have enabled “Always use HTTPS”.

The redirect from https://shuttersup.co.uk/ to https://www.shuttersup.co.uk/ is being done on your origin as the response contains headers not from Cloudflare. It is a 301 redirect though so that may not apply to every page.

curl -I https://shuttersup.co.uk/
HTTP/2 301
date: Tue, 05 Mar 2024 19:58:27 GMT
content-type: text/html; charset=UTF-8
location: https://www.shuttersup.co.uk/
x-pingback:
expires: Tue, 05 Mar 2024 20:58:27 GMT
cache-control: max-age=3600
x-redirect-by: WordPress
x-cache: MISS
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
access-control-allow-origin: *
cf-cache-status: DYNAMIC
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=nuXsKcusqGAZqX5dmkWxs0IQFBg%2BsEbrp0vZn6mJyCWOHE%2BVGNkoyfF2LbUfNtSjZ5t2UD6PQmz%2BzmV7EHZU3mZq2rIHnTaHWgxmPtOqCQ70uI2BfydTfRmi2CW9%2Fdss7pkL"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
server: cloudflare
cf-ray: 85fcae484c006419-LHR
alt-svc: h3=":443"; ma=86400

https://cf.sjr.org.uk/tools/check?898f18bcaffa461b924136fd0ef9f248#connection-server

Do you have an example of a link with a 302 redirect to check?

You can check for redirects set on Cloudflare in Page Rules or Redirect Rules…
https://dash.cloudflare.com/?to=/:account/:zone/rules/rules
https://dash.cloudflare.com/?to=/:account/:zone/rules/redirect-rules

1 Like

Thank you for the response, I really appreciate it. That makes sense regarding the top level page.

Despite this, the 302 redirects are appearing on every URL except for the top level URL.

For example, if you take https://shuttersup.co.uk/security, this redirects to Aluminium Plantation Shutters | ShuttersUp through 302.

That redirect is from your server, again the 302 response contains non-Cloudflare headers…
https://cf.sjr.org.uk/tools/check?7989f106fa634551a95ed7e1563a8326#connection-server

Although not always, I also get a direct response sometimes (same server, both use curl, doesn’t seem to be user agent dependent)…

curl -I https://shuttersup.co.uk/security
HTTP/2 200
date: Wed, 06 Mar 2024 10:44:49 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
link: <https://www.shuttersup.co.uk/wp-json/>; rel="https://api.w.org/"
link: <https://www.shuttersup.co.uk/wp-json/wp/v2/pages/41>; rel="alternate"; type="application/json"
link: <https://www.shuttersup.co.uk/?p=41>; rel=shortlink
x-cache: HIT
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
access-control-allow-origin: *
cf-cache-status: DYNAMIC
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=b92XVGkUK8Owpdk4OVtrb0sFTS1b5MUh049UkAZThK3n5%2FLJZrkDGTbrZsIRTn%2B4UcciKkQgeNd073odIB%2BAbAHdsYdUsy9fhurgUsfFau9%2BmVBaNihurxXCs%2Bnr7Sok9Y0N"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
server: cloudflare
cf-ray: 8601c0b01bcb63ae-LHR
alt-svc: h3=":443"; ma=86400
1 Like

Thank you again for the response, much appreciated.

So to confirm, this redirect is something set up on the hosting/server side, not Cloudflare?

Yes, the responses include headers from your origin server, so the response is coming from there. If Cloudflare was returning 302, those headers would not be there.

I can only get a 200 response from curl, but in the browser and the link to my tool, you can click the headers to see…
https://cf.sjr.org.uk/tools/check?0fc4fccf377b4894921499e3b947282f#connection-server

HTTP/2 302
date: Wed, 06 Mar 2024 15:04:47 GMT
content-type: text/html; charset=UTF-8
location: https://www.shuttersup.co.uk/security
link: ; rel="https://api.w.org/"
link: ; rel="alternate"; type="application/json"
link: ; rel=shortlink
x-cache: HIT
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
access-control-allow-origin: *
cf-cache-status: DYNAMIC
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=SM3VSdEJTBJZGOx6jyQpFvNrWoElbtiIZ8CsuFDFpvgjm%2BYFGjLgREwgFH9ReKT703OGgSsnbQIxxrsK7mzt6PR08kt3MNRu5cYhKb8kBOIb%2F4XBB6f7MNZUXStxec5G3m8k"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
server: cloudflare
cf-ray: 86033d811d586525-LHR
alt-svc: h3=":443"; ma=86400
2 Likes

Hi @developerinkdigital, your topic has a solution here.

Let us know what you think of the solution by logging in and give it a :+1: or :-1:.


Solutions help the person that asked the question and anyone else that sees the answer later. Login to tell us what you think of the solution with a :+1: or :-1:.

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