How to Redirect a URL (301 and 302 Guide)

Did you land on this site because you are seeking out different methods on how you can redirect a given URL?

Or perhaps you are a website owner who has changed his site to another and wants to drive the traffic from the old domain to the new one?

URL Redirecting or URL Forwarding is a technique used just for that purpose.

It can help lead users from your own domain name to another website or other active web page.

In this guide, we aim to show you different ways to redirect a URL, what types of URL redirects are there, and how to perform a browser redirect effectively.

How to Redirect a URL article image

So How Do I Redirect a URL?

First of all, you need to understand that there are different types of URL Redirects that exist out there. Here are they:

301 Redirect
This is a permanent redirect, meaning that it will stay as long as the two sites or pages are online. It is also an unmasked type of redirect that is used if you have permanently moved a web page or a web site. By doing this redirect, you will be able to drive absolutely ALL of the traffic from the old website to the new one with its SEO ranking. This means that how your old website ranked on Google will be automatically rerouted to match your new site and your new site will have the old site’s good rankings on hot topics in your niche. This is probably the best method for a redirect in terms of efficiency and SEO friendliness.

You would normally use 301 redirect if:

  • You move your site domain name to a new one and you want no delays and stopped traffic from your old to new site.
  • You try to make two sites into one via double 301 redirects and want to be certain that the discontinued redirects will lead to the new fresh site.
  • To simplify your own site. Sometimes, website owners tend to overdesign and “overURL” their site and this makes them way too complicated and full of links. If 3 different URLs lead to the same page, this 301 redirect is perfect for your situation. This also makes the site more SEO friendly.

302 Redirect
This type of UR redirect is contrary to 301, since it’s only temporary redirect to serve its purpose for a limited time. It is also an unmasked redirect that can be used for the same purposes we mentioned above in the 301 cases, but with the difference that here, the redirects are temporary. Examples for these unique cases include:

  • If your site is temporarily down due to outage, etc. and you want to temporarily lead users to a web page, that tells them there is technical difficulty or another site as well.
  • When you want to keep your primary URL you want to redirect from up there in goolge but you want the users who land on it to visit another page with the same topic that is updated with the newer content.

Masked Redirect (URL Frame)

This URL is also known as URL Frame and unlike 301 and 302, it is a masked one. So what is masked? Well, to most simply explain it, a masked URL is when the visitors on your domain are led to a given page or a site, but the new URL (to which you are led to) does not show. Instead, those users will see the same good old URL above, but the new site to which they are led below it. This is a clever way to redirect, but bear in mind that first of all, not all sites allow this type of redirect and more so, it is by far not the best choice for SEO – on the contrary, it’s even unhealthy for Google and other search engines.

Ways to Redirect a URL

steps to redirect url image

Okay, so now that you are an expert in knowing what types of URL redirects exist out there, lets learn how to do this. Below we have listed different methods to redirect URLs along with their accompanying step-by-step actions that you must take. We have tried to make it simple and cool so you do it fast.

Redirect URL Method 1: Creating a 301 Redirect in WordPress.

redirection plugin image

Creating a redirect in WordPress is a rather easy thing. Here is how to do it:

Step 1:Search for and install the “Redirection” plugin for WordPress.

Step 2:Go to Tools – Redirection.

Step 3:There you will see all of the 404 errors on your WordPress site. You will also see “Add new redirection”. Simply in Source URL type your OLD URL and in Target URL type your new one. After this, you should click “Add Redirection” and you are all set.

Redirect URL Method 2: WordPress Page Links To Plugin

page links to plugin image

Another method that is easy to use is via the Page Links To plugin. It’s a simple plugin that allows you to keep your post or page but also redirect it to another one.

Step 1:Add the “Page Links To” plugin.

Step 2:It should have added a box in your post edit screen. There you can add the address of the new location and later you can revert It to go back to its normal WordPress URL.

Redirect URL Method 3: Via WordPress Simple 301 Redirects Plugin

simple 301 redirects plugin image

Another easy plugin for redirects is called Simple 301 redirects. It allows you to make the most simple redirects.

Step 1: Install Simple 301 Redirects.

Step 2:Select the request and the destination for the redirect, after which click on “Save Changes”.

The only drawback is that with some specific hosting providers, this method for redirect could be a bit slower, so it’s important to have good hosting to use it and be sure to always test it out before directly deciding to use this plugin.

Redirect URL Method 4: Coding a 301 Redirect in a new .htaccess File (for Apache Servers and also WordPress via FTP Clients)

htaccess redirect image

Step 1:Find out if your website has an Apache server. If it does, it will have a file, ending in .htaccess extension. If you are unsure, do a checkup with your web hosting provider.

Step 2:Access your server via its IP address by typing it in the web browser.

Step 3:Once you have done this, you should see a menu to create a new file. Click on it and create a new file. Name the file “.htaccess” (the dot is very important). If your server does not have this option, you can simply make such a file In notepad and upload it to your server.

Step 4:In the already created .htaccess file, type the following code:

→ redirect 301 /old/

Tip: Be advised that the “oldsite” above is the name of the URL or the SITE you want a redirect FROM and the “newsite” represents the URL to redirect to. It is important not to add “http” or “https” before the OLD URL, because then the code will not work. The “301” represents the type of redirect you want to make, so you should’ve understood that you can make this 302 as well, given the right parameters.

Step 5:Click the dropdown box and select “all files” and after this simply save this file as an .htaccess file that has no extension whatsoever, only “.htaccess”.

Tip: It is important to backup your existing .htaccess files by renaming any existing .htaccess file to .htacessrecovery, for example. This will assist you to find and see the file in case you want to revert your site configuration to the “last known good site”.

Step 6:Upload and activate the redirect. Now that you have your .htaccess file saved and backed up, you should simply move it to the /root/ directory or if it’s a txt file on your computer – upload it. If so, there should be an Upload button on your Apache somewhere. And that’s it. Now you have a 301 redirect in Apache!

How to Test The Redirect:To test it simply save your browser passwords and reset your browser to factory settings or clean up its cache (even better).

Redirect URL Method 5: By Using an Online Redirection Site or Service

cpanel redirect image

There are many websites that offer redirects as a service, and to compete in this very competitive market, most hosting companies give you the opportunity to do it in your own cPanel (website control panel). This method is especially useful if you do not feel like learning to code and just want to click through the process and type the new URL.

Redirect URL Method 6: Redirect Via HTML “Meta” Tag

If you are a heavy worker on HTML and are more accustomed to the code site of things, then this is the type of redirect that you need. The Redirect Via HTML can happen if you have FTP access directly to your site. If you do, you can log in to where your server files are and access the HTML file which you are specifically interested in. From there, you can click on “Edit” to edit the HTML file in question. This will allow you to follow these steps.

Step 1:Edit the source code of the HTML file you have chosen the redirect to be in.

Step 2:Copy and paste this code where you set the old and new URL where it says.

→ <meta http-equiv="refresh" content="2;url=" />

Step 3:If you have done this right this is how your code should look like:

<meta http-equiv="refresh" content="2;url=" />
<title>Site Source</title>
This is the old page that will redirect to the new one

Redirect URL Method 7: Redirect a URL via PHP access

Via this method, you also require to have FTP access to edit your files. Here is how to do it:

Step 1: Create a PHP file, named ancient.php. Here is how it should start to appear.

→ <?php

This allows each time upon accessing the PHP file to get a redirect to a certain destination page or site.

Step 2:You can also add a description where it has been moved:

→ <?php
header("HTTP/1.1 301 Moved Permanently");

Redirect URL Method 8: By Using a JavaScript Service

JavaScript is a very interesting “out-of-the-box” type of coding language, so here is one way how to use redirects on it.

If you visit a certain URL’s code in the JavaScript, just change its location property on its “window.location”, kind of like this:

→ window.location = “”;

There are other types of methods via which can also work, like this:

→ window.location = “”;
window.location.href = “”;

Be advised that if you want this to successfully happen, you should make sure to test how it stands from SEO perspective (will its rank change) and also if you have enabled JavaScript.

Redirect URL Method 9: Via NGINX Redirect

If you have an NGINX Server, then you can enter the configuration file of your NGINX server and with few simple lines, you can set up a good 301 redirect for seconds time. Here is how:

Step 1:Locate and open your “nginx.conf” file to add a server block.

Step 2:Add the following redirect request code lines:

→ server {
listen 80;
return 301 $scheme://$request_uri;

Do not forget to make sure if your site is either http or https.

Redirect URL Method 10: If You Are Using Lighttpd Server

For the servers that are based on Lighttpd web server platform, it is strongly recommended to make a redirect by importing the “mod_redirect” web module and use it in a “url.redirect”. Here is how:

Step 1:Import the module, called “mod_redirect” in your Lighttpd web server.

Step 2:Set up a url.redirect via pasting the following code and changing the site parameters:

→ server.modules = (
$HTTP["host"] =~ "^(www\.)?$" {
url.redirect = (
"^/(.*)$" => "$1",

Redirect URL Method 11: Redirect on Ruby on Rails Web Server

If you happen to find yourself as an admin in the “Rails” platform, you can redirect quickly to a site. Here is how:

Step 1:Open the class WelcomeController < Application controller and use the following code:

→ class WelcomeController < ApplicationController def index redirect_to '', :status => :moved_permanently

In Ruby on Rails version for, you can make a redirect 301 via adding it in the “routes.rb” file:

→ get “/blog” => redirect(“”)

To redirect all of the pages, simply use this line:

→ get “/blog/:post” => redirect(“{post}”)

Redirect URL Method 12: Redirect on Node.js

Here are few quick steps to make a Node.js redirect:

Step 1:Make sure to add the http module and create a new server via the .writeHead type of method.

Step 2:Paste the following code and set the site to which you want it to go:

→ var http = require(“http”);
http.createServer(function(req, res) {
res.writeHead(301,{Location: ‘’});

To redirect all of the posts, simply go to your “/blog” section and paste this code where you modify the parameters:

→ var http = require(“http”);
var url = require(“url”);
http.createServer(function(req, res) {
var pathname = url.parse(req.url).pathname;
res.writeHead(301,{Location: ‘’ + pathname});

Redirect URL Method 12: Redirect on Flask Framework

To make a redirect on the Flash Framework, you can use the following steps:

Step 1:Get to the Flask Framework on top of Python.

Step 2:Simply paste the following code with modified parameters:

→ @app.route(‘/notes/‘)
def thing(page):
return redirect(“” + page, code=301)

How to Create a Website Redirect – Conclusion

These are most of the redirect situations you can find yourself in if you are a website server administrator. Of course, there are many others, alongside which there are plugins, websites, and services that vary a lot, but due to the sheer amount of them, we did not include all of them. We hope that you as admins let us know in the comments if you need information for other types of redirects you want this page updated with.

Leave a Comment

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.