Closed bryandugan closed 1 week ago
It definitely should not happen that a redirect would just "go away" when saved; it should either be saved, or an error should be displayed.
So I'm not sure this should be filed as a bug here -- have you contacted P&T to see if there is some kind of caching on Craft Cloud that could be affecting things here?
@bryandugan Craft Cloud will cache by default, so you are likely running into cached 404s.
You can force your 404 to not cache by putting this tag in: {% expires %}
: https://craftcms.com/docs/4.x/dev/tags.html#expires
In talking with @timkelty they are likely to change the behavior in how Craft Cloud works, so I'll close this up.
Also I want to note that Retour allows you to set header values in Retour -> Plugin Settings -> Additional Headers
So you could add in:
Cache-Control
-> no-cache, no-store, must-revalidate
I'm also going to add a higher-level setting to disable server caching of redirects that will do this automatically for you.
Ive tried adding in the header
Then I've tried adding the {% expires %}
tag and set it to in 1 hour (since it looks like there has to be an in, or on condition and then I've also tried {% do craft.app.response.setNoCacheHeaders() %}
which is what Brad had mentioned Craft uses for the Control Panel in Craft 5 without any luck.
I've also tried this using an incognito window.
since it looks like there has to be an in, or on condition
@bryandugan you don't need in/on. With no argument, it expires immediately, meaning no caching, which is what you want.
Your header value should just be no-cache, no-store, must-revalidate
. (should not contain Cache-Control ->
).
@timkelty Fixing the header value made it so that adding the redirect to the redirects section shows in the list, but I am still struggling with the 404 caching, so the fix isn't validated on the dashboard.
I have the following at the top of my 404.twig file:
{% extends "_layouts/_layout" %}
{% expires %}
However, I also have the following at the top of my _layout
file. I was previously having issues with the logged in state caching on each page and this fixed the issue there, but I assumed this may be conflicting with the {% expires %} tag
{% do craft.app.response.setNoCacheHeaders() %}
So In my Layout file I added with still no luck.
{% if not url('404') %}
{% do craft.app.response.setNoCacheHeaders() %}
{% endif %}
In the above commits, I added a Set No-Cache Headers setting (defaulting to on) to set no-cache
headers on the redirect response to prevent client-side caching
Craft CMS 3:
You can try it now by setting your semver in your composer.json
to look like this:
"nystudio107/craft-retour": "dev-develop as 3.2.17”,
Then do a composer clear-cache && composer update
…..
Craft CMS 4:
You can try it now by setting your semver in your composer.json
to look like this:
"nystudio107/craft-retour": "dev-develop-v4 as 4.1.18”,
Then do a composer clear-cache && composer update
…..
Craft CMS 5:
You can try it now by setting your semver in your composer.json
to look like this:
"nystudio107/craft-retour": "dev-develop-v5 as 5.0.2”,
Then do a composer clear-cache && composer update
As of craftcms/cloud:1.60
and craftcms/cloud:2.5
, only 200 responses are cached by default.
I just migrated a site over from WordPress to Craft Cloud, running Craft 5.2.2 and Retour 5.0.1.
Our SEO Agency was handling some redirects and noticed when an update was made like this and it was saved, it would be added to the re-directs list (sometimes), and other times, it would write and then go away.![CleanShot 2024-06-19 at 17 36 08](https://github.com/nystudio107/craft-retour/assets/4441531/1a996f9b-6c07-4079-ac00-1591d5214e0c)
Going back to the dashboard, the 404 File Not Found URL will still show, and that it hasn't been handled. In some cases, the redirect was written and clicking the path does redirect, but doesn't show up as handled.
I think it may be some sort of caching issue on the Craft Cloud side of things?
Also, as a minor annoyance, would it be possible to launch the "404 file not found url's in a new tab"? I accidentally click them all the time and have to click the back button.