How to redirect a URL to another URL: 4 methods

URL redirection is widely used for several reasons. There are many tools that help us make a simple and effective URL redirect. In this article, we will show some examples. If you wish to redirect the whole domain (any folder and page on it), then we recommend this article.

For SEO purposes, we always recommend using 301 Redirects (Permanent).

What is an URL Redirect

That means that when the visitor comes into the source (old) URL, it will be transferred automatically to the destination (new) URL.

There are basically two types of redirection: temporary (302) and permanent (301). Google values much more pages with permanent ones (301 Redirects), as per Matt Cuts. As a conclusion, we recommend using 301 Redirects whenever possible. Make sure you place the correct destination URL. Otherwise, you can lead to a 404 error page.

Method 1: Redirect URL using cPanel

By this method, you need access to your cPanel control panel. This is maybe the easiest and fastest method.

Firstly, access your cPanel control panel. Scroll down and find the Domains – Redirects icon, as shown in the photo. Then, click on it.

Then, we will explain how to configure the URL redirect in this screen. Firstly, we recommend keeping the field Type as Permanent (301).

Afterward, select the domain name you wish to redirect to outside. For instance, http://mysamplewebsite.com/specificpage.html is our source URL.

Under Redirects to, place the details of the destination URL. For example, we will redirect to http://www.anotherwebsite.com/.

Click Add, and the URL redirect is done! The source URL will redirect to another URL.

How to redirect a URL

Method 2: Redirect via HTML Meta tag

This is the solution about how to redirect a URL when you have FTP (or similar) access to your site. You just need access to edit the HTML files of the source URL you wish to redirect. Simply edit the specific source HTML file, and add this line to your <head> section.

<meta http-equiv="refresh" content="2;url=http://www.anotherwebsite.com/" />

For example, here’s how the HTML will look like:

<html>
<head>
<meta http-equiv="refresh" content="2;url=http://www.anotherwebsite.com" />
<title>Old page</title>
</head>
<body>
This is the old page that will redirect to the new one
</body>
</html>

Method 3: Redirect URL using PHP

Now, by this method, you need FTP access to edit files in your server as well. We will create a PHP file named old.php. Here’s how this file will look like:

<?php
header("Location: http://www.mynewwebsite.com/blog/"); 
?>

This way, whenever we access this specific PHP file, the user will be redirected to our destination site.

We can also use a more complete PHP file, specifying that this is a 301 redirect (permanent). In this case, the PHP file would look like:

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

Method 4: Redirect URL using .htaccess

This method consists in editing a file called .htaccess in your server and placing a specific line to make the URL redirection. Please note that the filename .htaccess really contains one “.” on its beginning!

This method requires FTP access to the server so that you can upload files.

Now, edit locally the .htaccess file.

You can choose one of the following code options. We will explain each one:

First alternative, redirect a specific page called /sourcepage.html to another URL:

Redirect 301 /sourcepage.html http://www.mynewdomain.com/

Second alternative, redirect the whole domain to another URL:

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

And last, redirect one file to another file, locally, in the same domain:

Redirect 301 /old/path/oldpage.html http://www.currentdomain.com/new/path/newpage.html

Was this helpful?

Thanks for your feedback!

Gustavo Carvalho

Leave a Reply

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