Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not override header; Remove Expires header #3600

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

PatelUtkarsh
Copy link

Do not override the header

Allows custom code to set cache control before calling wp_redirect.

Take the following code, which doesn't use custom cache control.

header( 'Cache-Control: max-age=86400, must-revalidate, public' );
wp_safe_redirect( user_trailingslashit( $redirect_to ), 301, 'custom-redirect' );
exit;

To make this work header call needs to be placed after the redirect call; note this requires ignoring VIP phpcs rule.

wp_safe_redirect( user_trailingslashit( $redirect_to ), 301, 'code' ); // phpcs:ignore WordPressVIPMinimum.Security.ExitAfterRedirect.NoExit
header( 'Cache-Control: max-age=86400, must-revalidate, public' );
exit;

Remove the Expires header.

The Expires header is ignored when cache-control is set: See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires

Note: If there is a Cache-Control header with the max-age or s-maxage directive in the response, the Expires header is ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant