10up/safe-redirect-manager

301 HTTP Status Code by default

JosVelasco opened this issue · 7 comments

Is your enhancement related to a problem? Please describe.

When creating a redirect rule, the default option is 302 Found redirect.

How many users want this option by default? Changing this is time-consuming when adding several redirects. A link explaining the different codes might be handy.

Designs

No response

Describe alternatives you've considered

Make the plugin remember the latest selected option.

Code of Conduct

  • I agree to follow this project's Code of Conduct

It's possible to change the default redirect status using the filter srm_default_direct_status, the following changes it to a 301 permanent redirect:

add_filter(
	'srm_default_direct_status',
	/**
	 * Set the default redirect status to 301 (Moved Permanently).
	 */
	function() {
		return 301;
	}
);

I'm afraid I can't find the original notes on why 302 was chosen as the default status but I suspect it was to allow testing of redirects before they are made permanent.

Once a browser follows a 301 redirect, it caches quite eagerly and it's just about impossible to break the browser's cache. Initially setting a redirect to 302 allows users to test the redirect before making it permanent and triggering the browser caching.

Perhaps documenting @peterwilsoncc's response, with some editing, into an FAQ in the README.md/readme.txt might be worthwhile / suffice for closing out this issue?

I agree, @jeffpaul.

Just a note with the first part of @peterwilsoncc 's response. That could be fantastic.

I tested the filter, and the HTTP Status changes to 301, but you must press the publish button twice.

I tested the filter, and the HTTP Status changes to 301, but you must press the publish button twice.

I'll check this out while working on the readme update.

It's okay if the user hits tab. The Publish button gets activated @peterwilsoncc.

@JosVelasco I created an issue to follow up the publish button issue as it looks to be JavaScript related and I didn't want to delay adding the docs for the issue. See #366.