Redirection using HTML, Javascript and .htaccess (in Apache)

Do you want to know how to redirect an html page and what are the various methods that you can use to redirect its Page URL to another?

What is Redirection?

Redirection is the technique of redirecting a web page URL to another.HTML Page redirection can be accomplished in several ways.This article will detail a few ways to accomplish a Web Page Redirect. If you are on WordPress, the most popular CMS used on the internet, here is a detailed guide on doing redirection in WordPress. Here are some other methods of doing Redirection for simple HTML Websites.

HTML Redirect using meta element for HTML Websites:

Though this is one of the most easiest ways to accomplish an HTML redirect, it isn’t the best way to redirect a web page.All you need to do is add a meta http-equiv tag to the head section of your HTML page. For example, adding the following code to the head section of html page will redirect it to “another-page.html” in 5 seconds.

<!-- HTML meta refresh URL redirection -->
   <meta http-equiv="refresh"
   content="5; url=">

In the above tag, the number preceding the “url=” ( 5 in this case), tells the browser to wait for so many seconds before redirecting to the new url – You could set this to 0 to do an instantaneous page redirect.

Javascript Redirection:

You can also redirect a page to another page using a simple javascript. To create a JavaScript redirect, place the following code between the head tags of your HTML page.You may replace the URL –, with the URL that you want to redirect to.

<script type="text/javascript">
window.location = ""

However the big disadvantage of a javascript redirect is not all users may turn on javascript in their browsers.Thus, if javascript is turned off, this redirection technique may not work.

.htaccess Redirect in Apache:

Another way (a better method) to accomplish an HTML redirect is by using a .htaccess file. However this will work only on an apache server and not on a windows server. However, you can check this article on how to create a 301 redirect on Microsoft IIS server.

  • Create a file on the root directory of your website and name it “.htaccess”. (create it in the root directory only if a .htaccess file does not exist already)
  • Open the .htaccess file using notepad or what ever text editor that you prefer.
  • Add the redirect command to the .htaccess file, save it and then upload it to your web server

Adding the following to the .htaccess file of the server in which the site (domain) is hosted, will redirect thispage.html to newpage.html in the same domain, say,

Redirect 301 /thispage.html

You could even redirect thispage.html to a new page on another domain as follows:

Redirect 301 /thispage.html

Note that in the above examples, you should not add “http://www” to the first part of the statement (i.e. /thispage.html). You should only mention the path from the top level of your site to the page. Also ensure that you leave a single space between the two elements.

If you want to redirect the entire traffic on the current site to the index page of the new site (, add the following code to the .htaccess file of the current site:

Redirect 301 /

The above are three different simple ways to accomplish a Page Redirect, though the .htaccess redirection is preferable over other methods explained here. However, note the example provided above for a .htaccess redirect is very basic.You could even accomplish more powerful web page redirection using Mod_Rewrite, which will be explained in detail, in another article.

Leave a Reply

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