HTML Redirection

My first useful post will talk about Html Redirection. It’s useful to know how make redirection.

Why do we need this stuff?

For instance, if you have moved an html page, but too many links point on this, you have to make a redirection page. If you are using a domain but your website is somewhere else, you can use this. If your website is in one folder, you can also do this.

So, I’m going to make it simple. There is 3 ways to make a redirection. The first one is to ask people to click on an link, like this : <a href="">Please go here</a>

The second way is to write this line in the head of the Html page : <meta http-equiv="refresh" content="0; url=" />

With this method, you can chose the time the redirection can make in content attribute. In the example above, the redirection is effective as soon as the page is loaded. If you want the redirection to be effective in five seconds, you have to write the line like this : <meta http-equiv="refresh" content="5; url=" />

The third way is the quickest way to make a redirection. You can write directly in the Html header with PHP to make a redirection. This is a code example :

//The order of lines bellow is important for compatibility
header('Location: '); //New address
header('HTTP/1.1 301 Moved Permanently');
header('Status: 301 Moved Permanently'); //For compatibility

Notice that for using php code, you have to create a PHP file. For instance : index.php

I’m using this code for my website. So, it’s working 😉