How to Create a Simple Redirect versus a PHP Redirect

Circumstances will often dictate that changes be made to your website, which could mean migrating the entire site or moving a single page to a new URL. Whatever the situation may be, redirects ensure your users are not left confused or even worse, lost. But that’s not the only purpose of redirects. Search engines use them to help in the content indexing process. In this post, we will explain what redirects are, why they are important, when to use them and, how to create simple and PHP redirects.

What is a redirect anyway?

A redirect is also called a URL redirection or URL forwarding. It is we send a page, form, or a website to a new URL address. To put another way, it’s when we send users and search engines to a URL separate from what they requested.

An example of this would be if you visited Hosting.UK/BlogA, but are sent or redirected Hosting.UK/BlogB.

What’s the goal of a redirect?

backup
Transfer files. Sharing files. Backup files. Migration concept. Communication between two computers.

Redirects are used to accomplish a number of goals, five such examples are:

  1. Dealing with website traffic during downtime or site maintenance.
  2. Re-routing a specific page to a new location
  3. Get rid of the “www.” portion of a URL
  4. Alter a site’s URL structure
  5. Permanently forward users to a different website

Three Types of Redirects

There are several different types of redirects. These include:

  • 301: “Moved Permanently
  • 302: “Found” or “Moved Temporarily”
  • Meta Refresh 

Let’s look at each separately, starting with the Moved Permanently redirect.

301: Moved Permanently

This reroutes users to another location and is touted as the best method when implementing redirects on a website.

302: Found / Moved Temporarily

Unlike its permanent counterpart noted above, this redirect is used to briefly reroute users. A 302 redirect may be used in the case where a page is going through maintenance that would prevent users from accessing that particular information or service.

Instead of leaving users wondering if they entered the wrong information or have them turn to competitors, a Found/Moved Temporarily redirect can prove essential.

Meta Refresh

If you’ve ever received an “If you are not redirected in five seconds, click here” message while browsing a site, you are familiar with Meta Refresh redirect. They are applied on the page as opposed to on the server and are generally linked to five-second countdowns with the text highlighted above.

What’s the difference between a simple redirect and a PHP redirect?

Simple Redirect: This allows users to redirect an entire website to another website by preserving the URL path and query string of the old site.

PHP Redirect: A PHP redirect enables users to navigate from one page to another without the need to click any hyperlinks.

There is a myriad of ways to redirect a URL, but for the purpose of this article we’re going to look at a simple redirect and a PHP redirect.

How to create a simple redirect using cPanel?

There are a number of straightforward steps involved in creating a simple redirect.

  1. You want to start by logging into your sea paddle using the information that your host would have given you when you initially signed up.
  2. The next thing you want to do it’s located the Domains section. Once that is found, select the Redirects option and choose the type of redirect that you want.
  3. Next up is to select the domain name that you want to redirect from the drop-down box that’s provided.
  4. Here is where you want to type the other portion of the path to the folder or file that you want to redirect.

With only few more steps to go you’re almost at the end of the process required to create a redirect.

  1. At this point type the full URL of the page, site or file that you want to redirect to into the Redirects To box. You need to include the protocol of the URL for the URL at this stage. The protocol for the URL is usually http://. 
  2. Next up is to select the type of www. redirection that you need.
  3. This next step is completely optional, but, if you want to have your redirects redirected to the same filename that is in the destination directory, you can select the wildcard redirect option to do it for you.
  4. Finally click add and your redirect should appear at the bottom of your screen.

If you get to the end and your redirects don’t line up with your expectations or achieve the object you set out at the start of the process, you’ll have to delete and recreate them because redirects cannot be edited.

How to create a PHP redirect?

  1. To generate a PHP redirect you’ll want to start by creating a file named php. This is done by using an FTP client or Secure Shell or SSH.
  2. The next step is to ensure the file is in the domain’s directory. The domain directory is what’s shown when you are adding the domain to your panel.
  3. To confirm that the file is in the domain’s directory, you can also navigate to the Manage Domains option and select the Edit button that is located to the right of the domain.
  4. Once the php file is created and confirmed, you’ll then add the line of code indicated below:
<?php header("Location: http://www.example.com/blog"); ?>
  1. Just remember to switch out example.com/blog to the actual URL that you want the site to forward.
  2. With all of that in place, you would have created a quick and simple redirection that you can then use to effortlessly redirect an HTTP request to any URL of your choosing.

Summary

Redirects are useful for several reasons. It’s therefore important that you choose the type of redirect you want based on what you are forwarding. But whether you opt for a simple URL or a PHP redirect, the process remains quick and straightforward. This allows you to cater to your users while carrying out maintenance or doing a complete overhaul of your site or a web page. For more tips visit your trusted website builder or web hosting provider’s knowledge base or blog for tutorials.