Log in

View Full Version : Best way to Redirect a page.



benslayton
03-07-2007, 04:41 AM
What is the best way to redirect a page? Meta refresh, php script, etc?:confused:

djr33
03-07-2007, 04:59 AM
Javascript works, but it relies on javascript, obviously, so that's the third best option.

The meta refresh is a great idea, if you only have access to the source.

If you have access to how the page is served, as in using PHP, then that's the best option.

The question is what you have access to for the use of each.

jscheuer1
03-07-2007, 05:09 AM
I think .htaccess is another even better way, if available. That may be PHP but, I think it's different.

http://www.webweaver.nu/html-tips/web-redirection.shtml

djr33
03-07-2007, 05:15 AM
Ah, yes, but that's a completely different solution in that .htaccess is a system wide setup, whereas the methods above are individual for each page.

Using either individually the PHP location header, or widely the .htaccess method would be good, I'd think.

If these aren't available, then using preferably meta or even javascipt would work too.

blueflowers
03-07-2007, 09:20 PM
to add to djr33's comment

>If these aren't available, then using preferably meta or even javascipt would work too

Meta is the best option of the two as it's SEO friendly :)

jscheuer1
03-07-2007, 11:00 PM
Ah, yes, but that's a completely different solution in that .htaccess is a system wide setup, whereas the methods above are individual for each page.

Using either individually the PHP location header, or widely the .htaccess method would be good, I'd think.

If these aren't available, then using preferably meta or even javascipt would work too.


Well a .htaccess file may be in a specific directory for only files in that directory. That much I have already come across and used for setting mime types with it. So, if your server supports .htaccess, you should be able to just use a single file in the directory in question with the redirect information for the file(s) in that directory.

djr33
03-08-2007, 05:11 AM
.htaccess seems like extra work as well as being not supported on all servers.
But if it works, sure.

jscheuer1
03-08-2007, 05:32 AM
.htaccess seems like extra work as well as being not supported on all servers.
But if it works, sure.

Not only that but, also it is far superior in many cases as, the redirected page never gets served at all, only the new page.

djr33
03-08-2007, 10:55 AM
PHP location header does the same, though it does send the page to the PHP engine which then sends the browser to the next page. I think.

techno_race
03-09-2007, 10:30 PM
Use <meta>

<meta http-equiv="refresh" content="1,myPage.htm">
seconds
page

jscheuer1
03-09-2007, 11:37 PM
Use <meta>

<meta http-equiv="refresh" content="1,myPage.htm">
seconds
page

Any particular reason why you think this is better than any of the other methods?

djr33
03-10-2007, 12:26 AM
This meta method has been mentioned, and the above code is wrong.

It's:
content="1;http://...."

The link should be absolute, not relative, though I believe this can work.
It should also be a semicolon (;) not comma (,).

Twey
03-10-2007, 12:39 AM
Send an HTTP redirect (3xx) status code followed by a Location header specifying the new location of the page.

djr33
03-10-2007, 04:29 AM
Using PHP this can be done.... I think.
Is that the same? Is there a way without PHP to do this?
(Let's just say that ASP=PHP=CGI for this... I'm sure there are SS programming languages that could.)

Twey
03-10-2007, 05:02 AM
Yes, any server-side programming language should be able to.
Is that the same? Is there a way without PHP to do this?It can be done with .htaccess (as mentioned above), CGI, or pretty much anything server-side, really.
Using PHP this can be done.... I think.Yes:
<?php
header('HTTP/1.1 302 Found');
header('Location: http://www.mysite.com/some/other/uri');
?>

techno_race
04-09-2007, 11:20 PM
This meta method has been mentioned, and the above code is wrong.

It's:
content="1;http://...."

The link should be absolute, not relative, though I believe this can work.
It should also be a semicolon (;) not comma (,).


Time to go with Amaya. Dreamweaver generated that. :rolleyes: (Talking to myself)

chechu
06-20-2007, 01:13 PM
I tried the meta mentioned above, but didn't work out.
How do I implement the below one ? If I call it index.php, will that be the first page to be found ? (I always thought it 'd be index.html). I just need an immediate redirect (instead of forwarding in a frame).

<?php
header('HTTP/1.1 302 Found');
header('Location: http://www.mysite.com');
?>

Twey
06-20-2007, 01:37 PM
This meta method has been mentioned, and the above code is wrong.

It's:
content="1;http://...."Actually,
content="1;url=http://..."
Time to go with Amaya. Dreamweaver generated that. :rolleyes: (Talking to myself)Don't use anything that generates your code for you.
If I call it index.php, will that be the first page to be found ? (I always thought it 'd be index.html).Depends on server configuration.

Some ways to redirect are, in order from the most supported:An HTTP redirect - the best option, if available; all HTTP clients should support these. How they're configured to be sent by the server (via server-side scripting [PHP, ASP, JSP...], configuration [.htaccess, modification of the global server config]) doesn't matter. A <meta> refresh - currently very well supported, but there is no guarantee that they always will be, or that clients will take notice of them even if they are supported; also requires the client to download part of the page, which is unnecessary overhead. Javascript - relies on client-side scripting and requires the client to download a larger part of the page. Plugin content - redirecting via Java, Flash, &c. requires the user to download the whole page, plus the external content, before redirecting. Anyone who actually uses this purely to redirect is an idiot.

alexjewell
06-20-2007, 01:39 PM
header('HTTP/1.1 302 Found');


Twey, why do you use the first header statement? What's the purpose?

Twey
06-20-2007, 01:45 PM
Read RFC2616, section 10.3 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3).

alexjewell
06-20-2007, 01:47 PM
Ok, makes sense. Thanks Twey.