HTTP redirect, meta refresh, Frame or JavaScript redirect

HTTP 301

A 301 redirect is an HTTP response to a browser request for a page. Here is how the server response looks like:

HTTP/1.1 301 Moved Permanently

As shown above, a 301 redirect means that the page has permanently moved to the specified location. All major search engines will


You can use the following code to trigger a 301 redirect in PHP:

header("Status: 301 Moved Permanently");


To redirect a single page using the .htaccess Apache configuration file, just add the following to the file:

Redirect 301 /dir/page.html


When the Apache module mod_rewrite is active on the server, you can use it to redirect visitors. Here an example:

RewriteEngine On
RewriteRule ^(.*)\.html$$1.html [R=301,L]

This will redirect all visitors from to

The advantage of this method is that you can write your rules so that the target URL changes based on the source URL e.g. to implement the following mappings:

  • to
  • to

HTTP 302

A 302 redirect is used to inform the browser/robots that the page has temporarily moved to a different location. So it should only be used when it is planned to host the redirected page back in the original URL after some time.

The redirected page keeps Page Rank, Page Authority and other metrics.  You thus have to pay attention when using it as the new page will not inherit any of it. So if you actually permanently moved the page but used a 302 redirect, you’re starting from scratch.

Although Google accepts 302 redirects and will not create major issues, Bing states the following:

We do not index any pages that have been 302 redirected by design.

So you basically have the risk that your pages will be indexed twice and you will be penalized for duplicate contents.

HTTP 307

The HTTP return code 307 is the successor of the return code 302 and was introduced in HTTP 1.1. This means that old systems only supporting HTTP 1.0 will not understand it.

This is also temporary redirect. It tells the calling user agent to redirect to a different page but not to forget this URL since it is only temporarily redirected.

To figure out whether to use a 302 or a 307 redirect, you need to check your web server log files. If you see that there are few HTTP 1.0 requests, then 307 is a good option. Otherwise you should probably stick to the 302 redirects.

Meta refresh

The meta refresh tag is a meta http-equiv tag to be inserted in the <head> section of web page. It will cause the browser to automatically refresh the webpage after a set period of time using the provided URL. It basically redirects the visitor to a new page.

It looks like this:

<meta http-equiv="refresh" content="...;url=..." />

Here’s what the Google Webmaster Tools say about the meta refresh tag:

This meta tag sends the user to a new URL after a certain amount of time, and is sometimes used as a simple form of redirection. However, it is not supported by all browsers and can be confusing to the user. The W3C recommends that this tag not be used. We recommend using a server-side 301 redirect instead.

And Google’s John Mueller:

In general, we recommend not using meta-refresh type redirects, as this can cause confusion with users (and search engine crawlers, who might mistake that for an attempted redirect). This is likely where the warning you saw came from. This is currently not causing any problems with regards to crawling, indexing, or ranking, but it would still be a good idea to remove that.

So although a meta refresh tag (also known as “the poor man’s 301 redirect”) with 0 seconds basically has the same goal as a 301 redirect (to immediately redirect the visitor), if possible, it makes more sense to use a 301 redirect.

The way meta refresh tags are interpreted vary across search engines:

  • Yahoo and Google treats zero seconds meta refreshes just like a 301 redirect.
  • Bing will not follow meta refreshes and will just skip the page.
Basically, you should avoid such redirects except if you do not have full access to the server and cannot setup a 301 redirect. In this case do not forget to also use a rel=”canonical” tag to tell the search engines where to find the new location of the page.
Also remember to only had a meta refresh tag but also remove the actual content from the redirected page (replacing by something saying the content is now somewhere else) just in case.

JavaScript redirect

JavaScript can also be used to redirect the user to a different page.

Here is how to redirect the user immediately:

    <script language="javascript" type="text/javascript">
      window.location.href = '';
// -->

As soon as the page is loaded, the JavaScript will be executed and replace the current URL by the new one.

You can also use the replace function instead of setting the href attribute:


instead of:

window.location.href = '';

Instead of this you may want to inform your visitors that they are being redirected and thus only activate the redirection once the visitor has had a chance to read the message:

<script language="javascript" type="text/javascript">
  window.setTimeout ('redirect_to ("")', 5000);

  function redirect_to (destination) {
    window.location.href = destination;
// -->

This basically instructs the browse to wait 5 seconds (5000 milliseconds) and call the function redirect_to which will update the current location in the browser.

So additionally to the JavaScript code you will want to display some kind of message (possibly with a link to the new URL in case the redirection doesn’t work).

Frame redirect

You can also achieve a kind of redirect by displaying the new page in an HTML frame. The advantage is that the visitor still sees the old URL in the address bar of the browser. The disadvantage is that it is a kind of cloaking method often used for phishing and spoofing. Another disadvantage is that the visitor then further navigates within the frame and the address bar in the browser doesn’t change. So it is not possible to bookmark a linked page after such a redirect.

The code looks like this:

  <frameset cols="100%,*" rows="*" frameborder=0 border=0>
    <frame src="">

One thought on “HTTP redirect, meta refresh, Frame or JavaScript redirect

  1. Nice article. however, you did not mention which one is the best in terms of of SEO friendliness. I believe the meta fresh tag is obsolete now and not at all recommended . so, what’s your pick?

    By the way, you js code is not working. Instead I tried

Leave a Reply

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