301 and 302 Redirect Rules

Redirects, or rewrites, are rules you can create to have certain URLs automatically go to a new location anywhere on the internet. If you have adjusted the URL structure on your website, and need former links to redirect to the new ones, you will need to configure redirect rules to ensure your pages can be found and maintain any SEO ranking.

NOTE

Looking for more complex rules to control traffic? Try the Web Rules Engine instead.

Need to redirect an entire domain to another (like www to non-www)? Try a domain-level redirect instead.


Redirects on WP Engine

WP Engine has deprecated the .htaccess file, meaning any redirects needs to be applied to your website with other methods. WP Engine has two areas of the User Portal to allow for easy management of redirect and rewrite rules.

  1. Create 301 or 302 redirects using the Redirect Rules page.
  2. Create rewrites using the Web Rules Engine.

Bulk Redirects

There are several ways to configure redirect rules, with the most effective ways being determined by the total number of redirects. All of the redirect options below offer bulk importing of Apache (htaccess-formatted) redirects. This means importing existing redirects from the .htaccess can be done quickly and easily, and does not require redirects be moved one at a time.

NOTE

Only redirect rules can be bulk imported. The Web Rules Engine (access, header, and rewrite rules) does not accept bulk imports at this time.

Fewer Than 1000 Redirects

More Than 1000 Redirects

  • Importing redirects into the WP Engine Nginx configuration will not be efficient at this quantity, due to bloating and overhead.
  • We suggest loading redirects into the Redirection plugin or, if you’re using Yoast SEO, manage redirects in Yoast Premium

NOTE

It is always recommended to consolidate as many rules as possible using RegEx, regardless of the number of redirects needed.


Access Redirect Rules

  1. Login to the User Portal
  2. Select the environment name you want to configure a redirect for
    • NOTE: Redirects for a specific domain will only work if the domain is also mapped to the same environment
  3. Select Redirect Rules

Add a Redirect Rule

The most common redirect is to simply have one page redirect to another. To set this up, click the New Redirect Rule button.

  1. Click New Redirect Rule
  1. You will be presented with a window like the following
  2. Configure your redirect and click Save or Add another

Redirect Rule Configuration Fields

It’s important to note that redirect rules will be read from top to bottom. If a rule is not specific

Redirect Name

  • A simple title to describe what the redirect is for
  • The name does not impact the redirect itself
  • Can be left blank, if a name is not given, a number will be applied

Domain

  • Use the dropdown to select the domain(s) this redirect will work for.
  • Select All Domains to allow the redirect to work for any domain mapped to this environment.
  • Select a specific domain mapped to your account to only apply the redirect to that domain, and no other domains.
    • For example, say this environment has the following domains: ilovepuppies.com, littledogs.com and dogshop.wpengine.com
    • Selecting ilovepuppies.com from the dropdown would tell the rule to only redirect requests to ilovepuppies.com and not redirect traffic coming into the same path through the domains dogshop.wpengine.com or littledogs.com.
  • For multisite networks with Domain Wildcarding enabled, you will also see an option called Use Domain Wildcards (Advanced). This option will use both the mapped domain and any wildcard domains.
  • If you do not see a domain listed that you’d like to set a unique redirect for, make sure the domain is mapped and remove any redirects to other domains.

Source

Reading the URL that you want to map from the left to the Right, the “Source” part will be whatever follows the domain. When looking at http://domain.com/testing/123, the “Source Input” would be: ^/testing/123

  • Required field
  • The original URL path that when requested will be redirected
  • Supports RegEx (A great tool to use to test your RegEx is RegEx101)
  • Do not enter the domain here
  • Start with the symbol ^ to say “begin here”, this is required for the source field unless you include the domain
  • End with the symbols /?$ to say “end here”
  • You cannot match a Query String, or Argument in the Source Input. You will need to look in the Advanced Settings in order to do this (details below).

EX: ^/old-page/?$

NOTE

If you capture something in the Source Input by placing parentheses around it, then you can call it later in the “Destination” using the $1 variable referrer.

Destination

  • Required field
  • The URL path the redirect will result in
  • Does not support RegEx

EX: https://ilovepuppies.com/new-page/

Variables set in the Source field can be called in the Destination field. With a Source Input of ^/testing/(123) and a Destination of http://domain.com/$1, then the Ending URL will be http://domain.com/123.

NOTE

Break type redirects have additional requirements for the Domain field. See the Break section below for more information.

If I have the following domains on this environment: ilovepuppies.comlittledogs.comdogshop.wpengine.com

The above rule would create all of the following redirects:

  • ilovepuppies.com/old-page -> https://ilovepuppies.com/new-page/
  • littledogs.com/old-page -> https://ilovepuppies.com/new-page/
  • dogshop.wpengine.com/old-page -> https://ilovepuppies.com/new-page/

Advanced Settings

Clicking on Advanced Settings will reveal two items:

Match args

An arg is another name for a URL query. You can spot them by a question mark in the URL. The “arg” is everything after the ? symbol. For example, in the URL domain.com/testing?input=thisthe arg would be input=this.

If you do not wish to have the arg carried over and appended to the destination, you must also add a ? to the end of your Destination source field.

If you do wish to have the arg appended to the destination, no question mark is necessary in the Destination source field.

EX: If the Source is domain.com/testing?input=this and the Destination is https://wpengine.com/testingthis/, this will redirect the URL to https://wpengine.com/testingthis/?input=this.

Rewrite type

This can be changed based on your preference of response codes.

301 Permanent – Default setting. Tells search engines to remove the old URL from the search index and update it with the new one.

302 Temporary – Tells search engines not to update their index. The purpose is to maintain SEO rank on the original Source URL. EX: Redirecting your home page to a “coming-soon” page.

Break – A “break” redirects the user to a different page on the same domain, without updating the address bar or sending a response code (301 or 302) is not returned. A break is also called also called an internal redirect, this can be used to “mask” a redirect. For example:

  • Domain: Select your domain
    • Cannot be “All domains”
  • Source: ^/my-page
    • Domain must match the Destination field
  • Destination: /backend_page?id=123
    • Domain must match the Source field
    • Do not use HTTP or HTTPS
  • This will load the content from /backend_page?id=123 while keeping the URL in the address bar as domain.com/my-page

Submitting Redirects in Bulk

If you’d like to import redirects in bulk this is entirely possible. You will need to reach out to WP Engine Support with a formatted file ready to import. Each rule must be on its own line to import properly and formatted similarly to the examples below.

The WP Engine User Portal supports up to about 1000 redirects. After 1000 redirect rules we’ve seen performance issues, so we strongly recommend keeping this list under the soft limit of 1000.

NOTE

302 (Temporary) rules cannot be bulk imported at this time, and will be converted to 301 (Permanent) automatically. Redirects can be changed to 302 after import via the User Portal, or set as 302 when added to the User Portal individually.

Before continuing, we recommend taking the following steps:

  • Perform an audit of the redirect rules. See if any are no longer needed, or if any of them follow the same pattern and can be grouped into “rewrites”, where requests matching a specific pattern are redirected based on that pattern.
  • Ensure the rules are in a text document (something easy to open and copy/paste from), and formatted like .htaccess redirect rules.*

If these rules are already in your site’s .htaccess file from a previous host, feel free to copy the rules and paste them into a .txt file for our Support team to import for you.

Bulk Import Formatting Examples

Redirect “domain.com/path/match/” to “domain.com/something/”

^/path/match/?$ http://domain.com/something/

Alternative format: Redirect “domain.com/path/match/” to “domain.com/something/”

Redirect 301 ^/path/match/?$ http://domain.com/something/

If there are multiple domains on an environment and you wish to redirect a single domain to a specific location

olddomain.com/path/match/?$ http://newdomain.com/something/

Redirect “domain.com/path/more/anything” to “domain.com/anything”

RewriteRule ^/path/more/(.*) http://domain.com/$1 [R=301,L]

Redirect a domain with an argument (?example-arg=123) on the end: “domain.com/path/match/?example-arg=123” to “domain.com/something/”

Redirect 301 ^/path/match/?example-arg=123 http://domain.com/something/


Additional Information

We use what is called Regular Expressions (also known as Regex) in the Source section of our redirects. Regular Expressions are very useful because they allow you to specifically create more advanced search strings which can be very beneficial for configuring advanced redirects. If you would like to learn more about how they work, please see our Common Regex Used For Redirect Rules article.

If you run into issues where a URL is redirecting somewhere unintended, look into the following:

  • Check any SEO or redirect plugins
  • Check your WP Engine server-level redirects
  • Review categories and trash for similar or conflicting URLs

If this does not resolve the issue, it may be because the post’s URL was changed and WordPress is trying help redirect the old post’s URL to the new one automatically. This is intended to be helpful but may cause issues if you are not aware of the functionality existing. If you wish to remove the redirect you’ll need to access the database and locate the wp_postmeta table, then clear out the _wp_old_slug value for the specific post.

Redirect Rule Order

When Organizing Redirect Rules, keep in mind that redirects will be applied from the top to the bottom.

In the example below, Rule 1 will be applied first because Rule 1 is placed above Rule 2.

Rule 1:

  • Source: ^/someurl
  • Destination: https://example1.com/

Rule 2:

  • Source: ^/someurl
  • Destination: https://example2.com/

NEXT STEP: Check out common examples of RegEx for redirects

Still need help? Contact support!

We offer support 24 hours a day, 7 days a week, 365 days a year. Log in to your account to get expert one-on-one help.

The best in WordPress hosting.

See why more customers prefer WP Engine over the competition.