Elegant Themes Blog

Stay up to date with our most recent news and updates

How To Create Redirects With WordPress

Posted on May 12 by in Tips & Tricks | 63 comments

How To Create Redirects With WordPress

In my recent guide to WordPress permalinks, I spoke about the need of choosing the correct permalink structure for your website from the start.

If you later decide to change your permalink structure, or if you remove posts or pages, you will generate 404 page errors. A 404 page error should be displayed to visitors when a page has been removed, however if the content has simply been moved to a different location on your website, you should redirect the visitor to the new location.

To see if your website has any 404 page errors, log into Google Webmaster Tools then go to the crawl section. In the Crawl Errors page, Google highlights any page of yours that Google is unable to index.

Google Crawl Errors

Google Webmaster Tools will advise you of any 404 page errors on your website.

There are other reasons why you would want to redirect a page, however for 99% of website owners, redirection is necessary when they change their URL structure or alter the post slug of an article.

In this article, I would like to show you how you can redirect a URL on a WordPress website.

What is a 301 Redirect?

The majority of redirects use what is known as a 301 redirect. This is named after the HTTP response status code 301, which informs search engines that a page has moved permanently.

Search engines advise website owners to use a 301 redirect whenever a page has permanently moved. 301 redirects ensure that page rank, and any other “juice” that a search engine gives a page, is transferred to its new URL.

There are other redirects available such as 307 (temporary) and 308 (permanent); however you should use 301 redirects whenever a page URL has changed so that search engine rankings and traffic are not affected.

How to Redirect a Page Using Htaccess

As I stressed last month, the .htaccess file has to be taken seriously. One incorrect character in your .htaccess file is enough to bring your whole website down. It is therefore vital that you create a backup of the file before you modify it. This will allow you to restore a working version of the file in the event of something go wrong.

You can create 301 redirects using the .htaccess file if you are using an apache server. All you have to do is specify the old location and the new location. You can do this with the following code:

Redirect 301 /oldpage.html http://www.yourwebsite.com/newpage.html

Folders can also be redirected in the same manner. You can also redirect a whole website with a 301 redirect using the following code:

Redirect 301 / http://www.yournewwebsite.com

All you need to do to check if your redirection is working is load the page you are redirecting. If its working correctly, you will be redirected to the new page.

How to Redirect a Page Using PHP

It is possible to apply redirects using many different languages including ASP, ColdFusion, Perl, and Java. You can even redirect a page by adding a meta tag into your page header by utilizing the http-equiv attribute.

WordPress uses the PHP platform, therefore if you integrate any other scripts with WordPress, they will probably use PHP too. If you find yourself in a situation where you need to redirect a PHP web page that is outside your WordPress installation, you can use a PHP redirect.

You can redirect a PHP page by adding this line of code to the header:

<?php 
header("HTTP/1.1 301 Moved Permanently"); 
header("Location: http://www.yournewwebsite.com"); 
?>

Note that the “301 Moved Permanently” line is necessary to advise search engines that you are using a 301 redirection. You also need to ensure that this code is placed at the top of the page to ensure the redirection works correctly.

If you would like to use redirection within a theme or plugin you are developing, you can use the WordPress wp_redirect function. The function will redirect links using a 302 redirect by default; however this can be changed by modifying the $status parameter.

How to Redirect a Page Using a WordPress Plugin

The beauty of WordPress is that you do not have to have a technical background in order to maintain your website. While you can use .htaccess or PHP to redirect pages, it is simpler to use one of many great redirect plugins available for WordPress.

One such solution is Quick Page/Post Redirect Plugin. The plugin allows you to perform 301, 302, 307, or meta refresh redirects.

Redirects can also have nofollow tags attached to them and be opened in new windows. All you have to do is check a box to enable this functionality.

Quick Page/Post Redirect Plugin

Quick Page/Post Redirect Plugin is a practical redirect solution that is easy to use.

Redirection is a great plugin that features 404 page monitoring. It will show you exactly what pages are generating 404 page errors and allow you to create 301, 302, and 307 redirects, for each of those links.

It allows you to redirect URLs to random blog posts or directly to your 404 error page. Redirections can also be allocated into groups to help you can manage all of your redirection links correctly.

Redirection

Redirection helps you find 404 page errors and allows you to redirect links to many other URLs and random posts.

Another solution is SEO Redirection Plugin. The plugin supports 301, 302, and 307 redirection. It also supports wildcard redirection and can automatically redirect any 404 errors it finds to a specific page.

SEO Redirection Plugin

SEO Redirection Plugin is one of the few plugins that supports wildcards.

I hope you have found this tutorial useful. If so, I encourage you to subscribe to the Elegant Themes blog for updates of our latest articles :)

Article thumbnail image by Dr. Cloud / shutterstock.com

63 Comments

  1. I never knew plugins existed for redirects until now. This is good to know. Thanks Kevin.

    • Kevin Muldoon

      No problem Adam. Yeah they are handy as they allow you to add redirects directly through the admin area. :)

      • Thank you Kevin !

        SEO Redirect is awesome. I have merge my HowToGhost blog to http://stupidcodez.com/
        First I have export and imported the posts and then Redirected all posts links. So, none of my search traffic dropped :-)

  2. Hey Kevin! Great article! I just had a quick question. I recently moved my wife’s food blog from normalcooking.wordpress.com to normalcooking.com. Obviously, the old blog was on WordPress servers, but the new one is a custom url on my personal hosting package with Host Gator. We are trying to monetize on her blog and she gets really great traffic (about 40,000/mo). Adsense rejects us time and time again (about 4 times) and we can’t figure out why. Do you think it might be because some of her blogs are redirected from her original blog (normalcooking.wordpress.com)? Would Adsense dislike the redirects like that? Thanks!

    • Kevin Muldoon

      If there is a 301 redirection sending all articles to their new location, it should be ok. It’s not like you are redirecting unrelated traffic to the website.

      I am not sure whether traffic levels are the reason for being rejected as you have enough. Your website design looks great too, therefore I do not seeing that being an issue.

      I was accepted into Adsense when it was first launched, so I do not know much about why websites get rejected. What did their rejection email say?

      • The email states that it’s because the site doesn’t abide by Google policies. However, looking over the Google policies, I can’t see where that’s the case. The email provided tips for us which were:

        1) “It’s important for sites displaying Google ads to offer significant value to the user. As a publisher, you must provide unique and relevant content that gives users a reason to visit your site first.” Lindsay’s site has original content on every post. Not only are the pictures original, but she types up original posts with each recipe. And obviously every post is relevant to the content that people are looking for when they come to her site.

        2) “Don’t place ads on auto-generated pages or pages with little to no original content.” We don’t have any auto-generated pages or pages with little or no original content. I created each page by hand, so nothing was automatic.

        3) “Your site should also provide a good user experience through clear navigation and organization. Users should be able to easily click through your pages and find the information they’re seeking.” The site obviously provides a good user experience. It’s very organized, easy to read, clear text and good use of colors. The index page and search option allow for users to navigate her site very easily, along with the tags and categories she puts on each post.

        At first when we were rejected we were thinking that it was because she was copying recipes and reposting them, however after looking at these policies, I find this to not be the case. The policy states:

        “AdSense publishers may not display Google ads on webpages with content protected by copyright law unless they have the necessary legal rights to display that content. This includes sites that display copyrighted material, sites hosting copyrighted files, or sites that provide links driving traffic to sites that contain copyrighted material. Please see our DMCA policy for more information.”

        The way she takes the recipes is completely legal and because she links back she isn’t doing anything wrong.

        The last change I made was to create a Privacy Policy that I’ve placed in under the About sub-menu. That didn’t help either. So I figured that it might be the redirects.

        I wish I could actually talk to someone within the Adsense program. That would help a lot! Sorry to get a little off topic though, I was mainly curious about the redirects and wondering if they might be the problem.

        • Kevin Muldoon

          I do not know for sure, but I suspect that using the exact same recipes is raising a duplicate content issue with Google.

          I checked a few of your articles through http://copyscape.com/ and they all highlight many other articles with the same content.

          I am not sure how Google handles this kind of thing. You would think that it allows text to be copied etc for the purpose of reviews. Perhaps it is the fact that all of your articles are raising duplication concerns.

          If one article had the same text, it may not be an issue, though if every article has the same text, it might suggest your website is simply scraping content.

          Again, I am only speculating at this point.

          Kevin

          • Kevin Muldoon

            Send me an email and I’ll set you up an account for Rise Forums. I don’t know the answer to this myself, though other members might have a better idea :)

  3. Nice article! Thanks!

    What about the performance? Isn’t it better to use the htaccess file instead of one more plugin!?

    • Kevin Muldoon

      It depends on the plugin. Some plugins use htaccess redirection, therefore it should be the same :)

      • Great article. Do you know which plugins are making use of the.htaccess?

        • Kevin Muldoon

          Not of the top of my head. Some of them give you the option of which type of redirection to use. If a plugin does not offer that option, my guess would be that it uses htaccess; though I would not know for sure without checking.

  4. I recently moved a blog to digital ocean. To my surprise they performance was super awesome compare to my old shared hosting. Now I need to set redirects and this article came just in time :)

  5. Thank you very much Kevin, I’m presently having a small issue with permalinks right now. I used custom permalinks to construct a community site I’m building but I changed to postname structure to suite a plugin and that generated 404 error page for one of my vip category page. I reverted to the custom permalinks and things return to normal but still render the hangout plugin registration pages useless, because I can’t get to the page front page when I linked to it. Maybe I will give some of the plugin you suggested a shot.

  6. Hi Kevin,

    I use Redirection plugin or .htaccess directives for SEO reasons, when I have a new site moved from another platform to WordPress.

    To find all links, first i catch them with Xenu’s Link Sleuth, copy them in an excel file, then redirects the old ones to new ones, where they are appropriate.

    Good to see some other plugins, I’ll try them all. Thank you for all valuable posts.

  7. I can’t even tell you what perfect timing this was for me! I just sent out this massive newsletter with 2-3 bad links! I should have checked, but am in the midst of a family emergency and just wanted to get the newsletter out! I WAS SO relieved to see this. Thank you! Problem solved. :)

  8. Hi Kevin

    Another great post. Thanks a lot.

    Every post from you is a lesson and I jumped immediately on this one for a try.

    I just installed “Redirection”. It is doing what is expected and easily. I’m used to track who is on line and what url they are requiring. Few minutes after installation, I have redirected 10 old .html URL to new ones. Just great and more secure than tweeking .htaccess file.

    Even more funny, one of our picture is used by a site without our agreement. I have designed a special picture for it, with a message to avoid copycat. Redirection allows to send the new picture instead of the ‘stolen’ one.

    Waiting eagerly for your next post !

    Cheers

    • Kevin Muldoon

      haha nice. I used to do that frequently with blog scrapers. They would frequently link to images hosted on my website, so I would take their domain and add a piece of hotlinking code to my htaccess file so that all of the images instead showed a picture of dog poo. Crude, but effective :)

  9. Hi, I don’t know if this comment will go through, I’ve been trying to comment but can not because your commenting box bounced my contribution twice. Is this selective regiment? What’s happening?

    • Kevin Muldoon

      I am not sure. Did you include a link in your comment?

      Comments with links are usually held in moderation.

  10. Thanks for the tutorial. I was completely unaware about the Redirect plugin. Surely I’ll try it.

  11. Handy and timely info for me, as I’m beginning to slowly migrate my asp.net sites over to WordPress, one paragraph at a time. So far I’ve just edited the .htaccess file, but will check out the plugins now also.

  12. Just Awesome Kevin : a complete guideline of redirect link in WordPress based website. Thanks for share

  13. I also use a bulk redirect plugin, complement of Quick 301 Redirect plugin.
    This plugin helps us to do a redirect of a specific page that we do not need to specific pages we want

  14. I am just wondering what the best way is, if you have many domains and redirect those to the main domain. The reason doing such is to measure different print campaigns (using those different domains) and Google Analytics doesn’t show 301 redirects (e.g. as referral). Any idea to how see redirects in Google Analytics?

  15. Thanks for all your posts Kevin, they are all very informative and helpful. I just wondered what you would suggest as being the best approach with regards to redirection for the following scenario. I’m looking to rebuild an older html website with a new version using wordpress. The site is hosted on a windows server with a cpanel that allows manual entry of redirects. The hosting company are not specifically wordpress orientated so I will need to set up the database and then do a manual install of wordpress, then set up the site. My question is, if I keep the same set up and rebuild the site with wordpress and manually set the redirects from the old html urls to the new wordpress urls, would this work best or alternatively I was considering moving the hosting and site to a more wordpress friendly hosting company and then doing the redirects once set up with the new hosting company. Obviously, if I move the site to a new host this involves the DNS as well. The site doesn’t have massive traffic but does ok. I feel however that traffic could be greatly improved by changing to wordpress and then working on the seo. Just not sure of the best approach to take as I dont want to trash the current traffic levels and ranking it currently has.

  16. Thanks Kevin, this article couldn’t come at a better time. Trying to set up redirects at the moment.

  17. What do you have to do i’ve you deleted 3000 tags and getting 3.000 -404- error pages into google webmaster tools? I’m running in such problem.

    Good post!

    • Kevin Muldoon

      First thing to do is to look at why you are generating that many 404 error pages. Have you changed your permalink structure? Have you deleted old posts or pages?

      • A few weeks ago i deleted 3.000 tags into my wordpress website because there was an overflow of unuesed tags. Now i’m getting those errors.. Any solutions…

  18. Great tutorial, thanks!

    Any plugipart from 301 redirection to other web-site, to have full controll over 404 page?
    How to have full control over 404? How to easily customize it? Any plugin here?

    By the way, I think it is time to add 404-customization option for Divi 2.0, don`t you think?

    • Kevin Muldoon

      Your theme should have a 404 template. You should be able to modify it through the template area or through the options area.

  19. Hostgator many times giving 500 Internal Error. I want to change the Hostgator Ad in that page. Any idea ?

    We are paying for them and when our blog gets traffic or sometimes they block the website and started showing their ads.

    • Kevin Muldoon

      I’d leave any hosting company that starting messing around with your website without your permission. Best to look for an alternative.

      • Sage advice Kevin! When companies start messing with your websites, it’s time to leave. And thanks for the very informative article and thoughtful replies.

        Was just looking for some good quality reasonably priced Word Press themes and was surprised to find so much excellent how-to content on the site. Way to go!

  20. Great article. You briefly mention performing an entire site redirect using the htaccess methodology. Is this the preferred practice? For example, I have a WP site mysite.com/folder and I would like to move the entire site to mysite.com, can I just 301 redirect the folder to the main site? Or is there a better way? BTW, if it’s a little more complicated, this would make a very valuable post for you to explain precisely how to perform this change, since its pretty confusing…

    Thanks for reading.

    • Kevin Muldoon

      Yes you can just redirect the full folder to your main website. That is what I would do.

  21. Hello Kevin,

    Thanks for this great article, it’s really helpful.

    We are trying to integrate our blog to our website and so switch our blog from domainname.wordpress.com to domainname.com/blog. The first link has no hosting so we can’t install this pluging. Do you know how we can redirect the links from the first to the second link?

    Thanks a lot!

    Amelie

  22. I run Shining Star Photo Booth, an event entertainment company that provides photo booth rentals. I have based my site on Chameleon (http://www.shiningstarphotobooth.com) and if I type in an invalid URL, it goes to a theme page saying those results do not exist. Is this the same as a valid 404 and 301 redirect?

  23. Thanks for the article it is very helpful and I think it is a piece of the puzzle I am trying to figure out for our library.

    I have created searchform.php in my theme in order to add a radio box below the search box. This radio box will allow a library patron to either search the site (using WP built in search), or search our library catalog (a hosted service on another site).

    I tried to use the javascript function window.location.assign(), but it appears that WordPress does not permit this. If I use the redirect plugin, could I then use the javascript window.location.assign() to make WP think that I am redirecting within the site and allow the plugin to take the user to the catalog site?

    Thanks

  24. Hello, I have a blog on wordpress.com and created another blog for a category in the previous blog. Now I want to redirect specific posts from the old blog address to the new one. All help I received previously talked about plugins, unfortunately i don’t code either. The problem is that I can’t see a plugin menu in my admin sidebar…can you help me? Can I do a redirect without codes and without plugins? Or can I get the plugin menu unto the admin bar?

    Thanks.

  25. Hi!

    Thank you so much for the article. I understand everything except (and this is a silly question) should I change all URLs first, i.e. the site I’m working on was never changed from Default permalink types and I need them on Postname- the site has been up a while, and I don’t want to affect the SEO they have….. So should I change the permalink type first and then write the redirections in the htacces. Or should I leave the permalinks on default, with the written redirections in the htaccess file acting as the new URLs?

    Sorry that may seem confusing but Im confused about where the new URLs are taken from…

  26. Thanks, Kevin! It had always seemed so intimidating!!!

  27. Hey Kevin,

    Great article, thanks for taking time to create it.

    What are your thoughts on Pretty Link?

    With appreciation,
    Ian Robinson

  28. Hi Kevin. Thanks for the tips. Any ways to redirect URLs within a free wordpress.com blog? thanks in advance. Anthony

Leave a Reply

Your email address will not be published. Required fields are marked *

Current ye@r *

Join 253,319 Happy Customers And Get Access To Our Entire Collection Of 87 Beautiful Themes For The Price Of One

We offer a 30 Day Money Back Guarantee, so joining is risk-free!

Sign Up Today

Pin It on Pinterest

Share This