10up / safe-redirect-manager

A simple HTTP redirection plugin for WordPress.
https://wordpress.org/plugins/safe-redirect-manager
GNU General Public License v2.0
311 stars 82 forks source link
http-redirects multisite-redirects redirect-manager redirect-plugins redirects safe-http-redirection url-redirection wordpress-plugin

Safe Redirect Manager

Safe Redirect Manager

Support Level WordPress tested up to version GPLv2 License Dependency Review WordPress Playground Demo

E2E test PHPUnit Linting PHPCS PHPCompatibility CodeQL

A WordPress plugin to safely manage your website's HTTP redirects.

Purpose

Safely manage your site's redirects the WordPress way. There are many redirect plugins available. Most of them store redirects in the options table or in custom tables. Most of them provide tons of unnecessary options. Some of them have serious performance implications (404 error logging). Safe Redirect Manager stores redirects as Custom Post Types. This makes your data portable and your website scalable. Safe Redirect Manager is built to handle enterprise level traffic and is used on major publishing websites. The plugin comes with only what you need following the WordPress mantra, decisions not options. Actions and filters make the plugin very extensible.

Installation

Install the plugin in WordPress. You can download a zip via GitHub and upload it using the WordPress plugin uploader ("Plugins" > "Add New" > "Upload Plugin").

Configuration

There are no overarching settings for this plugin. To manage redirects, navigate to the administration panel ("Tools" > "Safe Redirect Manager").

Each redirect contains a few fields that you can utilize:

"Redirect From"

This should be a path relative to the root of your WordPress installation. When someone visits your site with a path that matches this one, a redirect will occur. If your site is located at http://example.com/wp/ and you wanted to redirect http://example.com/wp/about to http://example.com, your "Redirect From" would be /about.

Clicking the "Enable Regex" checkbox allows you to use regular expressions in your path. There are many great tutorials on regular expressions.

You can also use wildcards in your "Redirect From" paths. By adding an * at the end of a URL, your redirect will match any request that starts with your "Redirect From". Wildcards support replacements. This means if you have a wildcard in your from path that matches a string, you can have that string replace a wildcard character in your "Redirect To" path. For example, if your "Redirect From" is /test/*, your "Redirect To" is http://google.com/*, and the requested path is /test/string, the user would be redirect to http://google.com/string.

"Redirect To"

This should be a path (i.e. /test) or a URL (i.e. http://example.com/wp/test). If a requested path matches "Redirect From", they will be redirected here. "Redirect To" supports wildcard and regular expression replacements.

"HTTP Status Code"

HTTP status codes are numbers that contain information about a request (i.e. whether it was successful, unauthorized, not found, etc). You should almost always use either 302 (temporarily moved) or 301 (permanently moved).

Note:

Filters

Default redirect status code

The default redirect HTTP status code can be changed using the srm_default_direct_status filter.

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

Redirect loops detection

By default redirect loop detection is disabled. To prevent redirect loops you can filter srm_check_for_possible_redirect_loops.

add_filter( 'srm_check_for_possible_redirect_loops', '__return_true' );

Only redirect if 404 occurs

By default every matched URL is redirected. To only redirect matched but not found URLs (i.e., 404 pages), use srm_redirect_only_on_404.

add_filter( 'srm_redirect_only_on_404', '__return_true' );

CLI commands

The following WP-CLI commands are supported by Safe Redirect Manager:

Development

Setup

Follow the configuration instructions above to setup the plugin. We recommend developing the plugin locally in an environment such as WP Local Docker.

Testing

Within the terminal change directories to the plugin folder. Initialize your unit testing environment by running the following command:

bash bin/install-wp-tests.sh database username password host version

Run the plugin tests:

phpunit

Issues

If you identify any errors or have an idea for improving the plugin, please open an issue.

Translations

Safe Redirect Manager is available in English and other languages. A listing of those languages and instructions for translating the plugin into other languages is available on Translating WordPress. Many thanks to the contributors on the translation teams!

Support Level

Stable: 10up is not planning to develop any new features for this, but will still respond to bug reports and security concerns. We welcome PRs, but any that include new features should be small and easy to integrate and should not include breaking changes. We otherwise intend to keep this tested up to the most recent version of WordPress.

Changelog

A complete listing of all notable changes to Safe Redirect Manager are documented in CHANGELOG.md.

Contributing

Please read CODE_OF_CONDUCT.md for details on our code of conduct, CONTRIBUTING.md for details on the process for submitting pull requests to us, and CREDITS.md for a listing of maintainers of, contributors to, and libraries used by Safe Redirect Manager.

Like what you see?