How to redirect a domain or web page

We all know about URL redirections and we’ve seen them many times during our experience of browsing the internet, and there is even a setting in your browser that allows you to be notified when websites are trying to redirect you to another web page. That being said, in this post we’ll see two examples of page redirections and how to redirect a domain or web page to another URL.

About redirects

Redirects allow you to make a specific web page redirect to another page and display the contents of that page. You could use a redirect for a long URL in favor of a shorter and easier to remember URL.

A permanent redirect will notify the visitor’s browser to update any bookmarks that are linked to the page that is being redirected (also called 301 redirect). Temporary redirects will not update the visitor’s bookmarks (also called 302 redirect).

Ok, so lets say you got yourself two domains (with your name for example) and two extensions (.com and .net) and you have your blog or website installed and running, but since you have two domains you most probably want them to display the same content. Of course, there are examples when there are different owners of the same domain name but with different extensions that don’t have nothing in common, but this topic is beyond the scope of this post. For now lets assume that you want to redirect a domain or web page to another domain (or URL). In this example I will use my domain as an example for redirection.

How to redirect a domain or web page using cPanel

The easy way of setting a redirection is to use your cPanel option where you just click the desired option, choose a domain or page (in case of multiple domains) and save your settings. Then the system generates .htaccess file in the root of your website with some rules that give the instructions to visitors’ browser about redirection to another URL.

How to redirect a domain or web using .htaccess file

If, for some reason, you don’t have the option of using the cPanel to set up the redirection you can also do that manually by creating .htaccess file (or editing the existing one if your website already uses it).

1. Open any text editor and enter the following lines of code:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^dejanjanosevic\.info$ [OR]
RewriteCond %{HTTP_HOST} ^www\.dejanjanosevic\.info$
RewriteRule ^/?$ "http\:\/\/dezareo\.me\/" [R=302,L]

The above example, as you can see, is 302 redirect and will not update the visitor’s bookmark. In case of 301 redirect the code should look like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^dejanjanosevic\.info$ [OR]
RewriteCond %{HTTP_HOST} ^www\.dejanjanosevic\.info$
RewriteRule ^/?$ "http\:\/\/dezareo\.me\/" [R=301,L]

2. Save your file as .htaccess

Your .htaccess file should be placed in the root of your website via FTP. Please note that in the root of your website you might already have an .htaccess file that may or may not contain additional code. Always make  a backup copy of it before making any changes because improper use of this file might cause your website to crash or show some errors.

 

0 comments

Leave a Reply