WWW FAQs: How do I redirect the browser to a new page?

2006-06-28: Redirecting the browser to a new page is easy. If you have a page at this URL:


And you always want the user to see this page instead:


It's very straightforward to send the user there, even if you don't have access to the Apache or IIS web server configuration settings. But first, we'll briefly look at what we can do if we do have that access, because there are advantages to redirecting that way. Then we'll move on to a simple HTML-based solution.

Sending a "Permanent" Redirect

Redirecting with PHP, ASP, or the redirection capabilities of both the Apache and IIS web servers has the advantage that your redirect will be understood by web search engines. That way, users searching for the old page automatically find the new one.

Permanent Redirection With IIS

To redirect with IIS, just do this, on the server (read on for other methods if you don't have access to the server):

1. Start -> Control Panel -> Administrative Tools -> Internet Information Services

These steps are correct for the Windows XP "Classic View." If you are using the standard view, the steps are slightly different:

Start -> Control Panel -> Performance and Maintenance -> Administrative Tools -> Internet Information Services

We recommend the "Classic View" for those who are running websites on their PCs.

2. Double-click "Websites," and then the website where the old page is

3. Locate the old page, right-click, and pick "Properties"

4. Beneath "When connecting to this resource, the content should come from," select "a redirection to a URL"

5. Enter the URL of the new page to the right of "Redirect to:"

6. If the redirection is permanent and you want search engines to know about it, check "a permanent redirection for this resource." If you are redirecting all traffic in an entire folder to a single new page, also check "the exact URL entered above."

7. Click "OK."

Permanent Redirection With Apache

The Apache web server also allows redirects. The easiest way, if your webmaster has configured Apache to allow it, is to create a file called .htaccess (note the dot in front!) in the folder containing the old page. Then add the following line to that file:

Redirect permanent /foldername/oldpage.html http://www.example.com/newpage.html

You can also redirect the entire folder and everything beneath it with this line:

Redirect permanent /foldername/ http://www.example.com/newpage.html

To redirect an entire site, use this line in the top-level web directory's .htaccess file:

Redirect permanent / http://www.example.com/newpage.html

More Permanent Redirection Tricks

For more permanent redirection techniques, see the 301 Redirect - How to create Redirects page on webconfs.com.

Redirecting In HTML

If you don't have the necessary access to use IIS or Apache redirects, you can still redirect the user in your HTML. Search engines might not figure out right away that the move is permanent and forget about the old page, but with care you can still give them a way to learn about the new page.

All you need is a <meta> HTML element, inside the <head> element of your old page, and a plain old <a> link in the <body> of the old page to please search engines. The following simple page redirects to another page:

content="5; url=http://www.example.com/newpage.html">
<title>Redirecting To Our New Page</title>
In a few seconds you will be redirected to our new page. If not,
just <a href="http://www.example.com/newpage.html">click on this
link to go to our new page.</a>

The key element here is <meta>, an element that can contain information that would normally be part of the HTTP response from the web server. By setting http-equiv to Refresh, we tell the browser we want to "refresh" the age. And by setting content to 5; url=..., we tell the browser that we want to go to the specified URL five seconds from now.

You'll note that my simple page also provides an ordinary <a> link to the new page. That's good practice because it allows users to find your new page if they have browsers or devices that reject or don't undetstand <meta> - a rare situation today, but it could happen, perhaps with a simple cell phone browser. More importantly, it allows search engines to index your new page, even if they fail to understand that you are redirecting to it in a permanent way.

Legal Note: yes, you may use sample HTML, Javascript, PHP and other code presented above in your own projects. You may not reproduce large portions of the text of the article without our express permission.

Got a LiveJournal account? Keep up with the latest articles in this FAQ by adding our syndicated feed to your friends list!