How to Redirect URLs in WordPress

Redirecting visitors from one page of a website to another is an important part of website maintenance, and there can be many reasons for doing so. This article will detail how to create redirects on your WordPress site.

While your WordPress site is running, it may be necessary to set up redirects to send visitors from one location on the site to another. Therefore, it is important to understand what redirects are, what they are for and how to set them up on your site.

At the same time, a very preferred and free WordPress redirection plugin is also recommended: Redirection , which is a must-have tool for WordPress.

What is URL redirection?

URL redirection can send visitors/crawlers from one URL on the site to another URL on the site.

For example, say you wrote a blog post at and now want to change it to Using URL redirection, it can be set up so that anyone visiting is automatically sent to

This improves the visitor’s experience by ensuring that they always have access to the content they want. For example, if they visit the test-2020 URL and see instead of a 404 error page, they can still access the latest content because they are automatically redirected to test-2021.

Redirects are also important for search engine optimization (SEO) because it preserves rankings and links. For example, got a lot of links from other sites to test-2020 posts (good for SEO). If no redirects are set, these links will lose traffic when the URL is changed. By redirecting, the weight of the new URL is preserved.

What can URL redirection be used for?

  • Change the URL of your content – ​​Whenever you change the URL  of a post or page on your WordPress site , you should set up redirects to avoid 404 errors and optimize SEO.
  • Fix broken content – If you see a lot of 404 errors on a URL on your website, you can set up redirects to send those visitors directly to the content they’re looking for.
  • Change the domain name of your site – If you change the domain name of your WordPress site, you should always set up a redirect so that visitors from the old domain are sent to the new domain.
  • Moving from HTTP to HTTPS  – When installing an SSL/TLS certificate, redirects should be set up to ensure that all visitors use the more secure version of HTTPS instead of HTTP.
  • Force www or non-www  – If you prefer or , you can set up redirects to force all your visitors to use the www version (and vice versa).

Different Types of URL Redirects and When to Use Them

To add a little more complexity, there are different types of redirects, each with a numeric code. All redirects function the same (send traffic from one place to another), but a numeric code is used to communicate additional information about the redirect to the user’s web browser and search engines like Google:

  • 301 Moved Permanently – This code indicates that the redirect is permanent. More specifically, the content is no longer at the original URL, but moved permanently to the new URL. This is the most common type of redirect and is very important for SEO because it passes “SEO weight” from the original URL to the new URL.
  • 302 (Temporary Redirect)  – This code indicates that the redirect is temporary. In other words, the content still exists at the original URL, but the user is temporarily sent to another page. This code is generally not used very often – it is only primarily used for A/B testing, maintenance or geo-targeting. 302 redirects should never be used for SEO.
  • 303  – This is very similar to a 302 redirect. The key difference is that it prevents users from submitting information (eg, credit card details) multiple times. In more technical details, it prevents the user’s browser from making another PUT request and tells it to use GET to handle subsequent requests.
  • 307 Temporary Redirects – Also very similar to 302/303 redirects. Again, the only difference is the technical details – 307 redirects use the same technique to send and get information, while 303 redirects use two different techniques.
  • 308 Permanent Redirect – Similar to a 301 redirect, this means the content has been moved permanently. The difference is in the technical details – 308 redirects can only use POST, while 301 redirects can be changed from POST to GET.

As a WordPress user, 301 redirects are almost always used to permanently redirect content for SEO purposes .

How to Create URL Redirects in WordPress

If your web host uses the Apache web server, you can set up redirects by editing your site’s .htaccess file. Note: Nginx server does not support .htaccess files , please skip the following 3 steps for Nginx server.

1. Find the .htaccess file

Connect to the site’s server via FTP or a tool like Pagoda Panel , find the .htaccess file in the site’s root folder.

Some WordPress SEO plugins also offer a dashboard .htaccess editor. For example, if you are using Yoast SEO , you can edit your .htaccess file by going to SEO → Tools → File Editor.

2. Backup the .htaccess file

Redirects can be tricky, and a small mistake can render part or all of a site inaccessible. Therefore, the existing .htaccess file must be backed up before making any changes.

If something goes wrong, all you need to do is re-upload the backup copy and the site will be back to normal in no time.

3. Add redirect settings

Place the following code at the top of the .htaccess file:

Redirect 301 /old-post

The above snippet redirects the visitor from to

Nginx server 301 jump rule

In the host configuration file add:

rewrite ^/old-post permanent;

How to redirect URLs with a WordPress plugin

If you don’t want to use your site’s .htaccess file directly, an easier option is to use a WordPress redirect plugin . The plugin can also create other types of redirects than 301, including 302 and 307 redirects.

How to set up server-level redirection

You may also encounter situations where you need to set up server-level redirects that affect every URL on your website. The three most common situations are:

  • HTTP to HTTPS – All traffic can be sent to the HTTPS version.
  • Non-www to www (and vice versa)  – can send all access to the www or non-www version of the content requested by the user.
  • Change Domain Name – All access to the old domain can be redirected to the same content on the new domain.

Redirect HTTP to HTTPS

Apache server add in .htaccess file:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

The Nginx server is added in the host configuration file:

    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;

redirect the entire domain

Apache server add in .htaccess file:

RewriteEngine on
RewriteRule (.*)$1 [R=301,L]

The Nginx server is added in the host configuration file:

if ($host != '' ) {
rewrite ^/(.*)$ //$1 permanent;


It’s important to understand how to use redirects in order to provide a great experience for your visitors and maximize your SEO results.

In most cases, only 301 redirects are required, but other types of redirects have their own niche uses (mostly for developers).

Leave a Comment