Beginner’s Guide to Creating Redirects in WordPress
Setting up redirects can be a regular task if you run a WordPress site. Particularly when you’re redesigning your website or making revisions to its permalink structure, changes to your URL structures are likely. Whenever that happens, the need for configuring redirects arises to ensure broken links don’t hurt the visitor experience and your hard-earned search engine rankings remain intact, for which you may have taken help from WordPress SEO experts.
Although WordPress core comes with redirect functionality designed to catch and correct incorrect URLs, it significantly impacts page loading speed and affects your site’s SEO. For instance, if you set up HTTP to HTTPS and non-www to www redirections simultaneously, the process becomes more complex, and you need to handle it manually.
Additionally, setting up manual redirects using certain HTTP redirect codes also helps you pass link juice from your old URL to the new one, which means you keep up your search engine rankings and link value. In this article, we’ll talk about different types of redirects in WordPress, how you can minimize them, and various ways and plugins you can use to set them up. Let’s dive in!
In This Article:
- What is a Redirect?
- When Should You Redirect a Page?
- Different Types of Redirects
- What is a 301 Redirect in WordPress?
- How to Create a 301 Redirect in WordPress?
- How to redirect an entire site or domain to a new one?
- How to redirect a page in WordPress?
- How to redirect an entire site to a subfolder?
- How to redirect a file extension to another while retaining the page name?
- How to redirect from an old domain to a new one?
- How to perform non-www to a www redirection?
- How to redirect HTTP to HTTPS in WordPress?
- How to remove an index.php and redirect to the root?
- How to redirect an old website to a new domain and pass the URL path to the new domain?
- How to redirect from a blog subdomain to a blog folder?
- How to redirect pages in WordPress using PHP?
- The Most Popular WordPress Redirect Plugins
- How to Minimize Redirects in WordPress?
- Conclusion
What is a Redirect?
URL Redirection, also called URL forwarding, is a technique for forwarding one URL to a different URL. It is a way to send users and search engine crawlers from the originally requested URL to a different URL where the pre-existing content is still available.
When the browser tries to open the URL they clicked on or entered in the address bar, a page with a different URL is opened. Similarly, when a URL domain – with all its pages – is redirected to a different domain, it is called domain redirection or domain forwarding.
Think of it this way: when you move to a new location, you have to contact the post office to handle a change of address. The post office then forwards the mail to your new address and informs the sender about the new address. The same thing happens on the web. Instead of forwarding your mail, you forward your users and search engines to a new web page.
When Should You Redirect a Page?
There are several scenarios when you may want to redirect URLs on your WordPress site, including:
- You’re moving or deleting a web page.
- The page’s URL is changing.
- You’re switching from HTTP To HTTPS.
- You’re moving web pages to a new domain or changing your original domain name.
- You’ve overhauled your website’s permalink structure.
- A specific page is no longer relevant.
- You’ve published an updated web page version and want to steer visitors away from the older version.
- You want to temporarily redirect visitors to a different page while updating a published page or post.
- You’re running limited-time deals and want to redirect the page to the original product page once the deal is over.
- You want to reserve similar top-level domain names for your business and refer them to your main website.
If there is no redirect implemented, your visitors will end up seeing a 404 error page. Chances are they will leave and possibly never return. Likewise, web crawlers will have no context of which web page to return for the user’s search query. Thus, implementing redirects in your WordPress site is inevitable to maintain your SEO rankings and deliver the best possible experience to users.
Different Types of Redirects
There are several different types of redirects, and each is made for a specific purpose. Understanding the differences between them will help you implement the best one for your particular scenario. Let’s take a look at the most common server-side redirect methods you might need to use.
#300 Multiple Choices:
The HTTP 300 redirect status response code indicates that the request has multiple responses, such as:
- Different languages
- Different filename extensions
- Multiple video format options
- Word-sense disambiguation
For example, if the browser cannot display an image in Web format, 300 redirection can be applied to serve the PNG version of the same image.
#301 Moved Permanently:
A 301 redirect is a permanent redirect that tells search engines the destination page has been moved permanently. Since HTTP 301 status code passes between 90-99% of link juice (or page authority) to the redirected web page, it is considered the most popular, convenient, and efficient way of redirecting a web page. Below are some circumstances when using a 301 permanent redirect proves a wiser option:
- When you’re planning to move or delete a web page permanently.
- You’re changing the permalinks of a post or page.
- When you’re permanently moving your website to another address.
- When you’re switching your website over to a new hosting service.
- When people use different URLs to reach your site, you can use 301 redirects to send traffic to your preferred URL.
- When you merge two websites and want to redirect the outdated URLs to the relevant web pages.
- When you want a seamless transition of traffic from your old site to the new one.
- You’re switching from an HTTP to an HTTPS.
- You have moved your site to a new CMS, and your permalink structure has changed.
However, keep in mind that the search engines may take some time to pass link juice, credit ratings, and rankings to the new page. This procedure might take longer if crawlers don’t go to the new page often or the redirection is not effectively applied.
#302 Temporary Redirect:
The 302 redirect is a temporary redirect that is used to tell search engines that the destination link has been changed for some time but not permanently. Unlike a 301 redirect, it does not pass on any link juice. Use the 302 redirect only under the following circumstances:
- When you want to redirect users to another page while keeping the original URL indexed.
- If your page is under maintenance and you want to divert traffic to another page temporarily.
- When your content is presented on one URL, but you’re promoting links to another URL.
- When you are setting up an online campaign or landing page.
You should use the 302 redirect with caution and only for testing browser compatibility. If you use this redirect for a long time, you may face SEO penalties.
#303 See Other Redirect:
The 303 redirect has the utmost importance in terms of security. It is often used as an alternative to the 302 redirect when a problem arises. A few web pages, like payment forms and landing pages, store one-time-only information. A 303 redirect prevents such pages from refreshing or bookmarking sensitive data such as credit card information.
This way, users can’t submit the same information more than once. Even they can’t re-submit forms if they hit the ‘back’ button in their browser. Once they successfully submit the information, they are redirected to a different page. This is done to prevent users from performing the same action twice. This redirect is used mostly on high-traffic eCommerce websites and does not influence SEO in any manner.
#304 Not Modified Redirection:
This type of redirect acts as an implicit redirection to a cached version of the requested page since no changes have been made.
#307 Temporary Redirect:
A 307 redirect is the HTTP 1.1 successor of the 302 redirect with changes in how information is passed from one page to another. It should only be used when the page is moved temporarily (such as during maintenance), and search engines identify the server as 1.1 compatible.
Since it’s nearly impossible to determine whether the search engines identified a page as compatible or not, it is recommended that you use a 302 redirect for a temporarily moved page.
#308 Permanent Redirect:
Like the 301 redirect, a 308 redirect is a permanent redirect used in case of a change in a file location. It parallels the behaviors of 301 redirect and passes on link juice to the redirected web page. The difference between the two is that it does not allow the HTTP method to change from POST to GET.
We can attribute a 308 redirect as a 307 redirect with permanent status. This type of redirect can be a good choice when you’re migrating your website from HTTP to HTTPS or restructuring it. However, in most cases, it’s best to use a 301.
There are also client-side redirects, but they are not as reliable as server-side redirects and should be avoided.
What is a 301 Redirect in WordPress?
As a WordPress user, you’d be mostly dealing with 301 redirects used for the pages that have been permanently moved. With the right setup, WordPress 301 redirect can improve site architecture, address outdated content issues, and improve the overall user experience while preserving your link diversity and search engine rankings. In most cases, this type of redirect transfers almost 90 percent of link juice to the new or updated page.
How to Create a 301 Redirect in WordPress?
There are several ways to implement redirects in WordPress. You can use a plugin or implement redirects through your site’s .htaccess file, which runs on Apache servers. The route you go for depends on the type of redirect you want to implement, the settings of your web hosting provider, and your comfort level.
The .htaccess is a distributed configuration file that tells Apache servers how to display files from the root directory and subdirectories. You can use an FTP application, such as FileZilla, to navigate your site’s root directory where the .htaccess file resides.
Download your .htaccess file from there and create a copy if something goes wrong and you need to restore the original version. It’s also advised you take a complete backup of your site before you get started. Listed below are some common .htaccess directives for redirection:
How to redirect an entire site or domain to a new one?
Open up your .htaccess file and add this code to the top:
Redirect 301 / http://www.example.com/
Replace example.com with your new domain name, and then save the file. This will permanently redirect every page on your WordPress site to the corresponding URL on the new domain.
How to redirect a page in WordPress?
To redirect a page to another URL in WordPress, enter the following lines at the top of your .htaccess file:
Redirect 301 /oldpost.php/ http://www.example.com/newpost.html/
You can use this redirect across different domains or on your own WordPress site.
How to redirect an entire site to a subfolder?
Use this command to redirect your WordPress site to a subfolder:
Redirect 301 / http://www.example.com/subfolder/
How to redirect a file extension to another while retaining the page name?
For instance, if you want a .html extension to use the same page name with the .php extension, use the following line of code:
RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php
How to redirect from an old domain to a new one?
If you’re moving your WordPress site to an entirely new domain, you’ll need to perform this redirect to preserve your SEO. Add the following snippet of code to the beginning of your .htaccess file:
RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
How to perform non-www to a www redirection?
For more flexible redirection, you can also use Apache mod_rewrite in your .htaccess file. For instance, here’s the code you can use to redirect from a non-www to a www subdomain.
RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
The above code snippet will apply the changes at the full-site level, helping you avoid poor user experience and page duplication.
How to redirect HTTP to HTTPS in WordPress?
If you have recently installed an SSL certificate and successfully migrated your WordPress site from HTTP to HTTPS, you’ll still need to implement a server-side redirect to eliminate duplicate content. Add the following code to your site’s .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
This code switches every URL under your previous domain from HTTP to HTTPS. If you’d prefer to use a plugin to perform this redirect, you can try Really Simple SSL.
How to remove an index.php and redirect to the root?
Add the following code to your site’s .htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index.php HTTP [NC]
RewriteRule (.*)index.php$ /$1 [R=301,L]
If you want to remove an index.html file, simply replace index.php with index.html in the above code.
How to redirect an old website to a new domain and pass the URL path to the new domain?
Use the following snippet of code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example-old\.com$ [NC]
RewriteRule ^(.*)$ http://www.example-new.com/$1 [R=301,L]
Change the last line to RewriteRule ^(.*)$ http://www.example-new.com/ [R=301,L] if you don’t want to retain the URL path.
How to redirect from a blog subdomain to a blog folder?
If you want to redirect blog.oldwebsite.com to www.newwebsite.com/blog/, add the code given below to your .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI}/ blog
RewriteRule ^(.*) http://www.example.com/%{REQUEST_URI} [R=302,NC]
RewriteRule ^(.*) http://www. example.com/blog/%{REQUEST_URI} [R=302,NC]
How to redirect pages in WordPress using PHP?
Here is how you can implement a 301 redirect using PHP:
<?php
header(“Location: https://www.example.com/”, true, 301);
exit();
?>
Likewise, you can implement 302 redirects by replacing the 301 code with 302 code.
The Most Popular WordPress Redirect Plugins
Like anything else, WordPress offers many plugins for implementing redirects on your website. It would be best to implement redirects manually, as installing plugins may add additional weight to your servers. However, if you are a WordPress novice who is not comfortable doing it manually, you can try these best options:
- Redirection
- 301 Redirects – Easy Redirect Manager
- Safe Redirect Manager
- Yoast SEO Premium
- RankMath
- Easy HTTPS Redirection (SSL)
- All 404 Redirect to Homepage
- 404 to 301
When choosing any other WordPress redirect plugin, be sure to pick the actively updated, well-reviewed, and widely used one.
How to Minimize Redirects in WordPress?
While it is essential and legitimate to use redirects in some cases, you should avoid using them whenever possible. This is because they slow down your WordPress site and often lead to a bad user experience.
For instance, if a user encounters a redirect, they might think they have landed on the wrong page and quit your website immediately. For this reason, you should not use too many redirects, as it might throw the requested page into a frustrating redirect loop. Hence, the best thing you can do to minimize redirects in WordPress is to optimize your website’s structure right from the start.
Here are a few things you can do to keep your redirects minimum:
- Never intentionally create unnecessary redirects.
- Make sure your site’s URL resolves with no more than one redirection.
- Configure the slug for each page or post before hitting the publish button, and make sure it is both user- and SEO-friendly.
- Configure your permalink settings to use pretty permalinks before you publish any pages or posts.
- Include or exclude the “www” subdomain as required.
- Use the proper protocol prefix (HTTP or HTTPS) from the very beginning.
- Include the entire path to the post or page.
- Avoid using page or post IDs in links.
- Clear out any plugins that you don’t really need. Some plugins can cause unnecessary redirects.
- Never link to a page that already has a redirect on it because it will only create a frustrating redirect loop.
- Regularly scan your website for redirects and fix redirect errors that might be causing problems.
Don’t worry! The redirect functionality built into WordPress acts as a fallback if you accidentally create a wrong URL. However, don’t take it as a very reliable fix for complex redirection errors.
Conclusion:-
Don’t underestimate the importance of redirects in WordPress. If you don’t configure redirects on your WordPress site, not only will it lead to a poor visitor experience, but also you will lose all those links that you have hard-earned to build up your website’s rankings in search engines. Consequently, you’ll have to start from scratch in terms of search engine optimization.
Therefore, redirects are a great tool to keep your website neat and preserve all your SEO efforts, especially when you’re working on on-site reorganization or launching a brand new website. If you need any help configuring redirects on your WordPress site, get in touch, and we’d be glad to assist you.