HTML Redirect

From Web Developer Network Wiki
Jump to: navigation, search

How to redirect users to a different page.

If you want to redirect from a page that is still there, or is linked to from many external sources, here's some code that will redirect them. Whenever possible, use HTTP redirects. HTTP redirects tells the browser the new location of the file it is looking for by sending a [HTTP status code (3xx)]. Files that are no longer there should be removed or coded to send a HTTP status code 301 (moved permanently).

  • If your server runs Apache and your server administrator has enabled [.htaccess], create a .htaccess file at the root directory with a line:
Redirect /oldpath http://server/newpath

For example, if we would like to make a redirect from to, we would create a .htaccess at our directory root with the following line:

Redirect /webdevnet/abc.html

  • If your server has PHP enabled, you may use the PHP header() function to make redirects.

For example, if we would like to make a redirect from to, we would replace the contents of abc.php with the following:



  • If none of those listed above are available, use this workaround.

<script type="text/javascript">
<meta http-equiv="refresh" content="0; URL=">

Just replace '' with the new URL.

Personal tools