How to Create Redirects with Redirection WordPress Plugin

Let's look at how to create redirects in WordPress with the Redirection plugin. A redirect is when one URL forwards to another. For example, https://optimwise.com/subscribe redirects to our MailChimp signup form. You can redirect from any URL inside your domain to:

  1. any URL inside your domain or
  2. any URL outside your domain.

The Redirection plugin is our go-to plugin for managing redirects in WordPress. It makes it easier for non-technical or less-technical people to manage redirects and tracks useful stats.

The Redirection plugin has many features and options. We'll just look at the most common ones. We'll work with 301 redirects, since they're extremely common. A 301 redirect signals that the content at a URL has permanently moved. It's useful when you create a new site and need to redirect pages to corresponding new URLs, or to redirect the URLs of content that you've deleted, or to redirect URLs that are giving 404 errors (file not found).

I created a video walking through a few examples. Below the video, I've included the examples in text.

Simple 301 Redirect

Let's say we want to redirect https://optimwise.com/work/ to https://optimwise.com/portfolio/. Here's how we'd create the redirect:

Source URL: /work/

Target URL: /portfolio/

Note: If the Target URL is on your site, you don't need to include the domain (in this case, https://optimwise.com) in the Target URL. Redirection will assume the Target URL is on your site unless you enter a different domain. If you're redirecting to a URL on your site, you really only need to enter the part after the domain, starting with a / (in this case, /portfolio/).

301 Redirect with Simple Regular Expression

Let's say we want to have a simple, memorable URL that redirects to our MailChimp signup form (which has a long, difficult-to-remember URL). We could create https://optimwise.com/subscribe as the URL we'll give people. Some people will type a slash at the end, and others won't. We want to make sure it works either way. We'd need to create a redirect with a regular expression. Here's how we'd create the redirect:

Source URL: ^/subscribe/?

Regex: enabled/checked

Target URL: /portfolio/ or just /portfolio/

The ? at the end of the Source URL tells it to match with or without the trailing slash.

Let's say you sell several types of shirts, and currently have URLs like https://domain.com/shirts/t-shirt and https://domain.com/shirts/long-sleeve-t-shirt, but you want to simplify and have a single page, https://domain.com/shirts/. Here's how you'd create the redirect:

Source URL: ^/shirts/.+

Regex: enabled/checked

Target URL: /shirts/

The .+ at the end of the Source URL tells it to match only URLs that have something after /shirts/, which prevents a redirect loop for https://domain.com/shirts/.

301 Redirect with Complex Regular Expression

Let's say that we used to have other pages under https://optimwise.com/work/ (such as https://optimwise.com/work/ron-meyer-excavating/) and now we want each of those URLs that contain https://optimwise.com/work/ to go to their new corresponding URL under https://optimwise.com/portfolio/ (such as https://optimwise.com/portfolio/ron-meyer-excavating/). We'd need to create a redirect with a regular expression. Here's how we'd create the redirect:

Source URL: ^/work/(.*)

Regex: enabled/checked

Target URL: /portfolio/$1 or just /portfolio/$1

This takes whatever string of characters comes after /work/ and drops it after /portfolio/. Basically, it substitutes /portfolio/ in for /work/ to create the new URL.

You can also use the (.*) wildcard without putting a variable (such as $1) in the Target URL. For example, when you share URLs in an email newsletter, or through social media, those platforms often attach extra characters to the URL for tracking purposes. Those could prevent your redirects from "seeing" them. To be safe, you can use the wildcard. Here's an example of how we do this for affiliate links:

Source URL: ^/go/flywheel(.*)

Regex: enabled/checked

Target URL: https://share.getf.ly/z02e2k

Resources

Leave Redirects to the Experts

If you're interested in creating redirects, you may be a technical person. Or, you may be a non-technical businessperson just trying to work with your website. If that's the case, there are probably hundreds of things you'd rather do than mess around with the technical aspects of your website. With OptimWise’s WordPress Maintenance Plans, we'll take care of your website, so you can take care of your business.

Filed Under: 
Tagged With: , ,

Want tips to rocket-boost your website?

Simply sign up.

70 comments on “How to Create Redirects with Redirection WordPress Plugin”

  1. Thank you so much for this article!

    Maybe it's just me, but I find a lot of wordpress plugins don't have a user manual on their wordpress plugin download pages.

    Before coming to your article I was on wpbeginner but their video & guide was short and didn't go into complete detail. SO thanks again for sharing this article, total godsend

    I started using wordpress a few months for the first time, and i'm totally loving it.

    1. You're, welcome, Michael. Yes, unfortunately, many WordPress plugins don't include documentation, or the documentation isn't as helpful as it could be. I'm glad to hear you're loving WordPress!

  2. All of these options are great. As we've done redesigns for our sites, we didn't always use the same WP permalinks. To maintain backlinks and avoid 404s, we need to find a way to force a trailing slash for all URLs but those directly to files like .html, .asp, .js, .png, etc. Previously, we used Yoast's WordPress SEO plugin. But the current version no longer has an enforce trailing slash option in their Permalinks section and I don't find anything online except references to the feature in older versions. So, I found the following expression to work at least in all my testing. It works for any directory hierarchy. I've done a ton of searches in Google and none provided this solution, so hopefully this will help a few folks.

    Source: ^/([^.]+[^/])$
    Target: /$1/

    Details: Using brackets means it's looking for at least one character. By adding the hat and only one item inside, it means it'll match any character but the one you have inside. We often use .* or .+ to capture all characters. So if you replace the period with the brackets, then you get a match for an entire URL as long as it doesn't have a period anywhere in it. The plus sign requires at least one character to be present. That makes sure the homepage isn't affected. Wrapping the hole thing but the first hat and slash puts the whole thing into a variable to pass along. You need the slash at the beginning to provide a boundary for the repeating wildcard and the last set of brackets basically look for the last character to be anything but a slash. I hope this helps folks!

    1. Daxon, this is awesome. Thanks so much for sharing what you learned with the world (at least the segment of the world that works with redirects).

    1. Not that I'm aware of, idzyns. I found this support thread where the author of the Redirection plugin says, Sorry, but a redirection cannot open in a new tab. In this later support thread, he says, It’s not possible to do this with a redirect. You will need to put _target=blank on your links. You could try that. I also found the Redirect To URL plugin that has the feature Open website in new Tab, but that plugin hasn't been updated in over 2 years, so I don't recommend it. If you find a solution, please comment here again to let us all know!

  3. Thank you so much. It saved my day! Just, when I try the redirect with a browser it does not work. Is it a matter of time till it will work? How long do I have to wait? Or did I do something wrong after all?

    1. Bernd, the redirect should work immediately. If it doesn't, it could be that you need to clear your cache. First, clear any cache on the website side (at the host level, or through a caching plugin). Next, clear your browser cache (or use an Incognito Window). If the redirect still doesn't work, then there's probably a problem with the redirect, so try recreating it.

      1. Chad, thank you. I made a mistake. For source I put in the URL with the www, It seems that was the mistake. I am still a bit confused: What is URL? Is it not like this: http://www.myname.de/ ? Is it always : http://myname.de/? We don´t need the www any longer?
        Thank you so much. Very kind of you to answer. Have a nice day.

        1. ...it seems even more complicated. After three redirects it does not work any more. Seems I have to wait for a day or so till I am able to do more redirects. It is confusing to me...

          1. I don't know why it would stop working, unless there's an error in the redirect itself. There shouldn't be any reason that you have to wait to create more redirects; we often create several and sometimes dozens of redirects on a single site in one day. It seems there's an error in the redirects, or your web host is blocking the ability of Redirection to create redirects. It may be worth asking your web hosting support.

        2. Bernd, the Source URL is the URL that you want to be redirected, when someone clicks it or types it in. It should be the full URL of the page or post that you want to redirect, not just the domain name. For example, the full URL of this blog post is https://optimwise.com/create-redirects-redirection-wordpress-plugin/. That's what you'd put into the Source URL field if you wanted to redirect it.

          Some websites use www in the address, and others don't. There's no universal rule; it depends how the website was set up. The www isn't necessary unless you have some internal networking reason for it; for example, some of our clients use the root domain (such as domain.com) for their internal network, so to avoid an address conflict they put their public website at www.domain.com.

          If your website uses www in the address, then you should include that in the Source URL. The Redirection plugin will strip the domain out anyway, so if you want, you could just include the part after the domain; in the example of https://optimwise.com/create-redirects-redirection-wordpress-plugin/, you could put just /create-redirects-redirection-wordpress-plugin/ in as the Source URL.

    1. John, the Redirection plugin can only catch URLs that match your current domain. To redirect your entire domain, you'll need to do domain forwarding (sometimes called a domain redirect). The control panel of many web hosts and domain registrars have tools for setting this up. If you don't see one, google the name of your web host and domain forwarding, or contact support for your web host or domain registrar. If your pages are still using the same permalinks, then you won't need to use the Redirection plugin to create redirects for them; the domain forwarding will send the old URLs to the new ones.

    1. Kristov, thank you for commenting. According to its plugin page, Redirect 404 To Homepage Redirects all 404 (Not Found) errors to the homepage. So, it's not an alternative to the Redirection plugin, because it doesn't allow the creation of redirects. I'm glad to see that the Details tabs says, this method is not recommended for all websites. … This is because in many cases, 404 errors should be analyzed on a regular basis and then 301 redirected to the appropriate page. I agree! It's better for users and search engines to have 404s redirected to an appropriate page than to redirect all 404s to the homepage. Thanks again for taking the time to comment!

  4. Hi Chad, Thanks for writing this useful article. This is the most detailed article which i have read recently, especially focus on Regex is quite praiseworthy, as most bloggers who wrote articles on using redirection plugin forgot to mention this important parameter. However I still have a doubt, for which I think you can throw some light. I recently moved from blogger to wordpress and my urls have this structure exa.com/2016/10/chanakya-secrets-for-children.html. Do i need to enable Regex check box if i want to redirect it to a simple url structure like this exa.com/coffee/best-coffee. As well as do i need to select url and referrer option in MATCH section so that i wouldn't lose any search engine rankings and visitors directly land on my site through proper url redirection.

    1. You're welcome, najariya! I appreciate the compliments. In the example you gave, it looks like you're changing everything in the URL after the domain name. In that case, you don't need to use regex. Regex (regular expressions) are used when you're matching patterns. So, if you were redirecting from exa.com/2016/10/best-coffee.html to exa.com/coffee/best-coffee, you could use regex to match the pattern and redirect multiple URLs with a single redirect.

      You don't need to use the URL and referrer option to preserve search rankings. As long as you create 301 redirects (which the Redirection plugin does by default), that will pass the link value. The URL and referrer option matches a URL when the source and referring site matches. In other words, it will match the URL only when the user came from a certain website. It doesn't sounds like you want that. To learn more about the match options, see Matching URLs in the plugin documentation.

  5. 1. I really appreciate the fact that Chad keeps answering comment questions and I've bookmarked this page. 2. Just in case anyone is wondering, if a URL contains url parameters / query strings, the (.*) solution works great as long as you indicate the redirect is regex and does not maintain the query string. 3. Is there a solution for maintaining query strings when redirecting to an external URL? Ex. domain.com/out/?_ga=X.XXXXX to newdomain.com?_ga=X.XXXXX

    Thank you in advance!!

    1. Michael, it's great to hear that you've found this post and its comments helpful! I'm afraid I don't have an easy answer for you on preserving query strings. 🙁 I googled redirection plugin url parameter query string and found some results that could be helpful (below). If they don't help, you could try other results of that Google search. You may need to create the redirects in .htaccess if the Redirection plugin can't handle them. If you find a working answer, please comment again!

  6. Hi Chad, I just followed your training step by step to redirect a post from one site domain to another.

    I went to the old post and click on the post to see if the redirect worked and it is still showing the old domain name.

    What could I have possibly done wrong? Does it take awhile to redirect to the new domain?

    1. I also just noticed that this post had 22 comments that did not follow through with the redirect. Is there a way that I can redirect posts and pages and have the comments follow it?

      1. Suzette, I'm not sure I understand the question. The comments should remain with the post; they're tied to the post in the WordPress database. If you change the URL of a post, that shouldn't affect the comments. If you're creating a redirect to a post on another WordPress site, that won't have any effect on the comments left on the original post.

        If you moved just the post to a different WordPress site, the comments won't automatically move with it. If you did a full export of your site's content, then the comments should go along with the posts they were originally attached to.

        Feel free to leave another comment with more details about the situation, and I'll help if I can.

    2. Suzette, the redirect should work immediately. If it doesn’t, it could be that you need to clear your cache. First, clear any cache on the website side (at the host level, or through a caching plugin). Next, clear your browser cache (or use an Incognito Window). If the redirect still doesn’t work, then there’s probably a problem with the redirect, so try recreating it.

    1. Ryan, I don't think the period/dot or the .php file extension should prevent a redirect from working. My guess is the problem is the URL parameter (AKA query string): the part starting with ?. I'm afraid I don't have an easy answer on that. 🙁 I googled redirection plugin url parameter query string and found some results that could be helpful (below). If they don't help, you could try other results of that Google search. You may need to create the redirects in .htaccess if the Redirection plugin can't handle them. If you find a working answer, please comment again!

      1. Hi Chad, thanks for the help! I did want to use the plugin, but may have to go back .htaccess to handle this one! If I find another solution, I will let you know!

        Thanks again!

  7. Hi, I watched your video and found, that this is exactly I was looking for (wildcard suuport and support for external redirections). Unfortunatly it does not work whene creating a simple reidrect to an external address. What could be the source of my problem (I double checked based on your explanation video)?

    btw: What is sorting code good for? Is it interpreted by the plugin during execution? Is there any logging or debuggin in order to find out, why my redirect isn't working?

    Any help is welcome!
    Manfred

    1. Manfred, if a redirect doesn’t work, it could be that you need to clear your cache. First, clear any cache on the website side (at the host level, or through a caching plugin). Next, clear your browser cache (or use an Incognito Window). If the redirect still doesn’t work, then there’s probably a problem with the redirect, so try recreating it. If you still have trouble, please comment again with more details on the redirect you're trying to create.

      I haven't used sorting, so I can't answer that. I'm not aware of logging or debugging built into the plugin, but I've never looked. Feel free to ask the plugin author about those items.

  8. Hi,

    Thanks for this its a great plugin. I am really struggling with the bulk upload functionality, would you PLEASE write a guide in order to help people have the correct format for .csv and and troubleshoot issues and what error's mean because I can't stand doing re-directs 1 by 1.

      1. Chad,
        Fantastic! That worked indeed! You have no idea how many things and like wildcards I tried in there. My redirect always went just to the top of the site, which was fine, but I needed it to be correct for one link. Now it's correct for all.

        Thanks so much!!
        Scott

          1. Hi Chad,
            I have another if you don't mind. I tried to apply what you said above, but couldn't make this work.

            I still need the one you gave me in place for the url above:

            http://site.com/product/example-page —-> http://site.com/example-page

            That one is working great, except now I need another variation to do this;

            http://site.com/product/example-page-ebook —-> http://site.com/example-page

            So it's just adding on the -ebook at the end of the first url and going to the same url

            Thanks!

          2. Scott, the way I read it, the example-page part changes based on the URL, but the ebook part is the same across several URLs. If that's right, I believe this will work:
            Source URL: /product/(.*)-ebook
            Target URL: /$1
            Check the box for Regex.

  9. Hi Chad,

    This new one did not work, but then I disabled the other one you gave me before and it worked. So it seems only one will work at a time, and the previous one seems to take precedent when both enabled. Is there a way to combine these or have them both work at the same time?

    Thanks so much for your help!
    Scott

      1. Chad, that worked. I didn't know that order thing mattered. One was zero along with another one. And the other was 31 along with a different one. Now they are all different with the -ebook one lower as you said. Thanks again so much!

        1. Hi Chad,
          This is working great, like magic. Just a quick question. I I didn't purposely set it, but one is 301 and one is 302. Should they both be one or the other?

          Thanks,
          Scott

          1. Scott, you should use 301 if you don't intend to use the Source URL in the future. 301 transfers more of the link value (sometimes called link juice) to the Destination URL. Use 302 if the redirect is temporary, and you intend to use the Source URL again in the future. Here's what Moz and Network Solutions have to say about 301 vs. 302.

  10. Hi Chad, Thanks for your elaborate information. I'm glad to have found this plugin! But what happens with the redirects when you deactivate or remove the redirections-plugin?

    1. Madonna, if all the URLs that end in .html need to be redirected to the same URL without the .html, you can set up a regular expression (regex):

      Source URL: /(.*).html
      Target URL: /$1
      Check box for Regex

      That will replace post.html with post, redirecting as you requested.

      I should point out that WordPress URLs for pages and posts end in a trailing slash (/), so I recommend setting up your redirects to include the trailing slash:

      Source URL: /(.*).html
      Target URL: /$1/
      Check box for Regex

      If all the URLs don't fit a pattern as described above, then you'll need to create a redirect for each URL.

      1. Thanks Chad, I tried the .html redirect but with .php files after moving to wordpress. The problem is it affects the wp-login.php file. Is there any regex expression that can redirect .php files 'except' wordpress' own files that contain 'wp-'?

        1. Pieman, I'm afraid I don't have an answer. We haven't had to bulk redirect to remove the .php extension, so I can't speak from experience. Perhaps someone else reading the comments can chime in, or you may need to google for answers. If you find an answer, please come back and add it here!

    1. Fredrik, I’m afraid I don’t have a quick answer, and I don't know when I'll have time to research. If you haven't already looked at the Resources section of this blog post, start there. Or perhaps someone else reading the comments can chime in, or you may need to google for answers. If you find an answer, please come back and add it here!

  11. Chad, thanks. This was great. I do have another question along the same line. For example, if I want to redirect an entire site (and all subfolders and pages) to another URL (domain), BUT I still need to have access to logging into either https://sitename.com/wp-login.php or https://sitename.com/wp-admin/, and to view the site (after logging in) so I can see the site (as if it wasn’t being redirected), how can I set this up in the Redirection plugin? If you can help, what would the settings (including the regex) be for each part? Thanks. Gary

    1. Gary, I'm afraid I don't have an answer. If you had the domains/sites on different servers, you could use your hosts file to change the IP address that the domain resolves to. Basically, you can bypass DNS and force your machine to use a certain IP address for a certain domain. Here's how to do that on a Mac, and in Windows. But if your domains/sites are on the same server (and same IP address), I don't have a solution.

  12. Thank you so much. It saved my day! Just, when I try the redirect with a browser it does not work. Is it a matter of time till it will work? How long do I have to wait? Or did I do something wrong after all?

    1. Acha, the redirect should work immediately. If it doesn’t, it could be that you need to clear your cache. First, clear any cache on the website side (at the host level, or through a caching plugin). Next, clear your browser cache (or use an Incognito Window). If the redirect still doesn’t work, then there’s probably a problem with the redirect, so try recreating it.

  13. Any recommendations on how to set up an auto redirect?

    For example if I wanted to delete a bunch of old posts is there a setting that would automatically redirect them to home page or page of my choice?

    1. Nathan, if you delete old posts without creating redirects, then users will get 404 (file not found) error pages. You can use a plugin (such as All 404 Redirect to Homepage) or code to redirect all 404s to the homepage (or another page), but it's better for users and search engines if you redirect each of those deleted posts to an appropriate page, using the method described above.

    1. Ucel, if other sites link to one of the URLs that you've redirected, those users who click that link will be redirected to the Target URL that you set. If I misunderstood your question, feel free to ask again. An example helps me understand questions better.

  14. Hi Chad,

    I use the 404 to homepage mentioned above by Kristov because I found loads of traffic just seeming to look for non existent pages like https://oursite.com/fred or https://oursite.com/kjglh etc.

    I've used Redirection to fix all URL spelling changes, as well as some other more complicated stuff.

    Now I'm trying to trim the number of plugins I'm using, so I was wondering if I can set up Redirection to do what 404 to homepage does, so I can eliminate that plugin?

    I tried about half dozen ways, but can't get it. Is this possible in Redirection?

    Thanks,
    Scott

  15. Hello,

    Any recommendations on how to set up an auto-redirect?

    For example, if I wanted to delete a bunch of old posts is there a setting that would automatically redirect them to the home page or page of my choice?

    Please tell me.

    1. There are plugins that will redirect 404 (Not Found) errors to the homepage or another page you choose. If you deleted those posts, then users would get 404s when trying to access them. It's better for users and search engines to have posts or pages be 301 redirected to an appropriate page than to redirect all 404s to the homepage or another page, but if you want, you can look at these plugins.

Ready to Blast Off?

Let's talk.

Contact OptimWise
crossmenuarrow-right