There are times when website administrators or website owners need to implement redirects, specially when URL of an existing page is changed then visitors should be redirected to the new URL. In this article we will cover what is a 301 redirect, why and when should we create a 301 redirect in WordPress and how to create 301 redirects in WordPress.
If you are just interested in how to create a redirect in WordPress, scroll down to “How to create a 301 redirect in WordPress” and learn about the three Different ways to create a redirect in WordPress.
What is a 301 Redirect:
301 redirect is a permanent redirect. Creating a 301 redirect is giving a permanent job to the server, that look out for visitors and send them at the specified address. 301 Redirects may be implemented domain wise or page wise, domain wise redirects are useful when we change a website’s domain name and don’t want to loose our visitors.
When should we create a 301 Redirect:
- URL or Permalink of a post or page is changed.
- A post or page is removed or moved to a new domain.
- If name or slug of a category is changed.
- If the entire site’s domain name is changed.
- Want to rank a specific post or page.
Why 301 Redirect is Important?
- To not loose your visitors
- For providing good user experience.
- For the sake of SEO.
Redirects are important if you do not want your visitors to be presented with 404 content not found error and staying good in the eyes of search engines. It is a good practice to direct users to another good related page, instead of presenting them with 404 not found error.
How to Create a 301 Redirect in WordPress:
In WordPress you can create 301 redirects by any of the below three methods, starting from the easy one.
- By using WordPress Plugins.
- Through coding with wp_redirect WordPress function.
- Creating 301 Redirects by editing .htaccess file.
WordPress redirection plugins:
There are a number of free plugins available in WordPress repository for creating redirects easily. Following are the most popular WordPress plugins for redirection.
1. Redirection :
Redirection is the most high rated and popular redirection WordPress plugin. This plugins helps you easily create 301 redirects, helps you manage all 301 redirects and this plugin also help you keep track of 404 errors.
Redirection plugin also supports regix patterns which helps you to create redirect patterns which can match to any number of URLS.
You can configure Redirection plugin so that it can automatically detect and create redirect when a post or page URL is changed.
2. 301 Redirects
With 301 Redirects you can manage and create 301, 302, 307 redirects in your wordpress admin dashboard, for improving user experience and SEO of your WordPress site.
Creating redirect with wp_redirect wordpress function:
This option is for you if you are familiar with WordPress programming and editing your WordPress site’s php files.
Following is the wordpress built-in function for creating a redirect, but you should note that for making it to work properly you need to create a function in functions.php or in a new plugin and specify there, which posts or pages should be redirected.
wp_redirect( "http://www.your-site.com/new-destination-url", 301 );
Creating 301 redirect with .htaccess file:
.htaccess file is a powerful configuration file found in the root directory of your site. This type of redirects are very fast and do not overload the server. If you are not familiar with .htaccess then you should not make any changes to this file, because a single coma can make your site in accessible.
This is how to add a redirect to the .htaccess file. the following code is for redirecting a single page/post to a new page/post. You just need to write your page/post URL by replacing the example URLs.
Redirect 301 /old-page.html http://www.example.com/new-page.html
In WordPress 301 redirects can be created by three ways, 1. By using WordPress plugins, 2. Using wp_header function in wordpress functions.php or in plugins, 3. Through editing .htaccess server configuration file.
Using WordPress Plugins for creating redirects is the easiest option which do not require any basic coding skills or advance knowledge of wordpress.
Using wp_header WordPress function requires coding and development knowledge of WordPress, you should use this option if you are familiar with wordpress development and template structure.
.htaccess is a server configuration file located at the root directory of your site. Creating redirect through .htaccess file requires access to site’s root directory, it should be done with caution because a single mistake of comma can make your entire site inaccessible. Although redirect created through .htaccess are fast compared to other methods, and these do not put any load on the server.
Hope that we have helped you, help us by sharing this on social media with your friends.