How to Redirect a Web Page (HTML, Apache and PHP redirects)

Redirecting is the process to take the visitors to a new page when they visit a certain expired or non-existing webpage. Redirecting changes the old URL to a new URL.

For example: I had redirected this website from “” to ““. That was domain-level redirect.

In this website, if you click this link “” it automatically changes to “”. That is, site-level redirect.

I will discuss the following different methods for redirecting (you can choose only one). If you are unsure of which one to choose, just go with HTML Redirect because, it is the easiest and has less impact in the site configurations:

  • HTML Redirect
  • Apache Redirects
  • PHP Redirects

HTML Redirects

Meta Refresh tag can be used to redirect from an existing page to a new location. In the HTML file of the old page, locate the <head> section at the top and insert the following redirecting code:

<meta http-equiv="refresh" content="0; URL=''" />

If you are redirecting domain root (main page) to another domain root, past the above code in the index.html or index.htm file of the domain folder replace the “” by your new domain name.

Apache Redirects

As most of the websites are hosted on Apache servers, Apache redirects is a very common method of redirecting a web page. For this a file “.htaccess” found on the Apache web server should be edited and added a code. The file “.htaccess” is where the commands to be given to the server are saved.

To redirect the website or sub-folders, new .htaccess file can be created. If there is already a “.htaccess” file located in the root directory or sub-folder, it should be opened and the following code should be added:

Redirect 301 /

Redirecting a sub-folder (blog or website) to a new domain:
RedirectMatch 301 /sub_folder(.*)$1

Redirecting individual pages can be done by

Redirect 301 /things.htm

PHP Redirects

A “header’ function can be used in PHP to redirect websites. The following code should be used in the top of the PHP file like “index.php” or something like to redirect to the new website.

header('Location:', true, 301);


Leave a Reply

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