views:

26

answers:

1

I need to implement a forwarding. I did it the following way:

<html>
<head>
<meta http-equiv="refresh" content="0; URL=http://www.xyz.com"&gt;
</head>
<body>
</body>
</html>

Are there any situations in which this won't work? I read on selfhtml.org (http://de.selfhtml.org/html/kopfdaten/meta.htm#weiterleitung, sry for the german link couldn't find another) that this isn't always appropriate. Are there any better ways to do this? And in which situations my code wouldn't work?

+3  A: 

Well, the major argument against is what the linked page already says: The user's browser could have meta redirects turned off (although this is going to be rare), and immediate redirects can cause usability problems when the user tries to navigate through the history.

If you can, though, don't output any HTML at all, but do a server-side redirect using the location header. In PHP, it would look like this:

<? header("Location: http://www.xyz.com");
   die();
?>

if you can't do that, I'd say using a meta redirect is fine. You could add a few seconds' pause and a message ("You are now being redirected to...."), combined with a link, to minimize annoyance for users.

As for Search engine optimization, Search engines, I expect, will silently ignore the redirecting page, and go on indexing the target site, which is probably what one wants.

Pekka
You will likely also want to set the HTTP status code to one of the 300 family. http://www.websitepulse.com/kb/3xx_HTTP_status_codes.html
Conspicuous Compiler
@Conspicuous good point. The `Location` header sends a 302 by default.
Pekka
thanks pekka this works perfectly well@conspicuous compiler ill check it thanks
Roflcoptr