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: If you are in the process of migrating your account and you are not using redirects, you can move on to the next section of the migration process.


Redirects on WP Engine

At WP Engine we use a server setup that utilizes the Nginx over Apache. All requests hit Nginx first, which means redirects are served more quickly when placed there. Apache is slower and is also subject to caching, which can cause redirects to not work as intended.

You’ll want to setup all of your 301 and 302 redirects in your User Portal (which serves from Nginx) instead of other ways such as using the .htaccess file or using plugins (which serves from Apache).


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 RegEx Pal)
  • 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 do not you 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.

Our User Portal supports up to about 1000 redirects to be imported. After about 1000 redirect rules, we’ve seen performance issues, so we strongly recommend keeping this list under that amount.

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.

When Organizing Redirect Rules, keep in mind that the Rules will be applied from the top to the bottom. For example, if you have a specific rule like ^/testing/123/abc/?$ with the Destination /123/abc/; and then another more Generic, “Catch All” rule of ^/testing/.* with the destination of https://wpengine.com/, then you should have the second rule at the bottom of the redirect list, and the first rule at the top.
This will ensure that the two redirects won’t conflict with each other. If you put the second rule at the top, then it will “catch-all” before the more specific rule has a chance to take effect.


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.