Redirecting/forwarding a website – URL redirection

There are different ways for you to redirect a domain to another one or, in general, one URL to another. Most of the available options are explained in this article:

1. Using our URL Redirection tool
In your Web Hosting Control Panel you will find the URL Redirection section (Advanced > Admin Tools > URL Redirection), from where you can set up URL redirection. For detailed information about the options, please click on the Show/Hide Help link.

2. Framed redirection
If you want to redirect visitors but keep the URL (address) in the address bar unchanged, you have to use framed redirection. Basically, what you do is create a file that loads the new website (which you want to redirect to) in a frame. To use framed redirection to redirect my-best-domain.com to my-best-domain.net, for example, you can create a file called index.html and put it inside the main folder of my-best-domain.com. The index.html file must have the following code:

<html>
<head>
<title>TITLE OF THE PAGE</title>
<frameset cols = "100%">
<frame src ="http://my-best-domain.net" />
</frameset>
</head>
<body>
</body>
</html>

Of course, make sure to replace “TITLE OF THE PAGE” with the actual title that you want your visitors to see and replace “http://my-best-domain.net” with the actual web address, which you want to redirect the visitors to.

(3) Using .htaccess and the Redirect directive

If you need to forward visitors to the new address and don’t mind that the URL in the address bar will change, you can use the following technique:

Create a file called .htaccess inside the main folder of your domain. You can do this using the File Manager (Site Management > File Manager) section of your Web Hosting Control Panel. Edit the .htaccess file to put the following code in it:

 

Redirect 301 / http://my-best-domain.net/

The above code will redirect visitors to http://my-best-domain.net/ and “tell” search engine spiders (bots) that your URL has changed permanently – this is what the 301 code means.

Using this technique you can also redirect specific URLs, for example a single page. If you used to have a page called page.html and you renamed it to newpage.html, you may want to create a redirection, which will forward visitors who try to open page.html to newpage.html. This is how it’s done with .htaccess:

 

Redirect 301 /page.html http://my-best-domain.com/newpage.html

*Additional uses of .htaccess:

  • You have changed the file extension?
    RedirectMatch 301 (.*)\.html$ http://my-best-domain.com$1.php

    This example is perfect if you have decided to switch from .html pages to .php, keeping the old names of the pages and changing only the file extensions. Now, be careful with this because any .html page there is will be redirected to a page with the same name but with a .php extension, regardless of whether such .php file actually exists.

  • Redirect all www traffic to a NON www version of the site (http://www.my-best-domain.com -> http://my-best-domain.com):

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www.my-best-domain.com [NC]
    RewriteRule ^(.*)$ http://my-best-domain.com/$1 [L,R=301]
  • Redirect all NON www traffic to a www version of the site (http://my-best-domain.com -> http://www.my-best-domain.com):

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^my-best-domain.com [NC]
    RewriteRule ^(.*)$ http://www.my-best-domain.com/$1 [L,R=301]
  • You have purchased SSL for your domain and now wish to redirect ALL traffic to an HTTPS version of your site?
RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*)$ https://www.my-best-domain.com/$1 [R]

 

(4) Redirecting using the META tag refresh
In HTML files you can put a META tag refresh to refresh the page after a certain amount of time. The META tag refresh also allows you to refresh to a new URL, which virtually means forwarding the visitors to a new web address. To use this technique you must create an index.html file inside your domain’s main folder with the following code:

<META http-equiv="refresh" content="0;URL=http://my-best-domain.com">

This will redirect the visitor immediately to my-best-domain.com.

(5) Using the Location Header in PHP
This technique works similarly to the afore-mentioned one where we redirected the visitor using the HTML META tag refresh. However, instead an index.html file, here you must create an index.php file inside your domain’s main folder and use the following code:

<?
header("HTTP/1.1 301 Moved Permanently");
header ("Location: http://www.my-best-domain.net");
?>

This will redirect the visitor to http://www.my-best-domain.net and will “tell” search engine bots that the address has changed permanently.

(6) Redirecting using JavaScript
Control over what page is loaded into the browser rests in the JavaScript window.location property. By setting window.location equal to a new URL, you will in turn change the current webpage to the one that is specified. If you want to redirect all your visitors to www.my-best-domain.net when they arrive at your site, you will just need the script below:

<script type="text/javascript">
<!--
window.location = "http://www.my-best-domain.net/"
//-->
</script>