Redirecting a URL...?

They have: 71 posts

Joined: Sep 2002

Hello fellow webmasters! I have been out here everyone now and then, but I have a question. We are currently working on a website dedicated to Microsoft's games. We would like the ability to redirect a certain URL to another URL without the visitor having to wait for the redirect for even a second. Does anyone know how this is done through a code or some other means? I would greatly appreciate a response!

Thanks once again!
Robby Laughing out loud

nike_guy_man's picture

They have: 840 posts

Joined: Sep 2000

You can use the header() function in PHP if you have support for PHP
http://www.php.net/manual/en/function.header.php

<?php
The second special
case is the \"Location:\" header. Not only does it send this header back to the browser, but it also returns a REDIRECT (302) status code to the browser unless some 3xx status code has already been set.



header(\"Location: <a href=\"http://www.example.com/\" class=\"bb-url\">http://www.example.com/</a>\"); /* Redirect browser */
exit;                 /* Make sure that code below does
                         not get executed when we redirect. */


?>

Smiling

You can use Meta refresh in HTML, but that is on a delay

Laughing out loud

He has: 1,016 posts

Joined: May 2002

Create a file called "redirect.php", inside it put...

<?php
header
("Location: $_REQUEST[url]");
?>

Then you simply link to the file... request.php?url=http://www.microsoft.com/ which will send the user to M$ website, or request.php?url=http://www.google.com/ which will send the user to google.

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

Quote: Originally posted by zollet
Create a file called "redirect.php", inside it put...

[b]

<?php
header
("Location: $_REQUEST[url]");
?>

Then you simply link to the file... request.php?url=http://www.microsoft.com/ which will send the user to M$ website, or request.php?url=http://www.google.com/ which will send the user to google. [/B]

...what?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

I guess it's possible to answer a question too clearly! lol!

Create a file called request.php. That file should only have this in it:

<?php
header
(\"Location: $_REQUEST[url]\");
?>

Then, on the pages where you want to redirect people to another url from your page, put:

microsoft

instead of:

microsoft

Why?

Well, in this case, you could add more options to request.php to track hits to that link, and then you could display on your page how many times someone clicked from your page to microsoft.

However, I think that KnightRobby was asking a slightly different question?

If the page the people land on isn't the one you want them to stay on, you can use a meta refresh of 0 seconds (but there is a perceptile delay), or you can put, on the page you don't want them to stay on, the php snip redirecting them to the correct page.

I believe that someone just asked this question here in this forum to display two different headers depending on what site someone came from.

Is that accurate KnightRobby?

(And, Zollet, thanks, I have been meaning to research the ?url= part for ages!)

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

o ok i think i get it now Smiling :S

He has: 1,016 posts

Joined: May 2002

Quote: Originally posted by Suzanne
(And, Zollet, thanks, I have been meaning to research the ?url= part for ages!)

You are more than welcome Smiling

openmind's picture

He has: 945 posts

Joined: Aug 2001

Just for a bit of variety!

In ColdFusion:

  <cflocation="www.whateverurl.com">
'

Always more than one way! Smiling

They have: 71 posts

Joined: Sep 2002

Okay, I tried the code and I get something called a "parse error." And I am not sure if you all may know exactly what I am asking:

Let's say a visitor goes to webquad.com When they reach that page, I want it to immediately forward or redirect them to, as an example, Microsft.com How do I go about doing this properly? If your coding is right, sorry, but I am getting an error still...and a simple link on the page...?

Thanks for the replies!
Robby Laughing out loud

Busy's picture

He has: 6,151 posts

Joined: May 2001

what does the error say
and what version of PHP are you using?

He has: 1,016 posts

Joined: May 2002

Robby,

Edit your index.php and on the first line type...

<?php
header
("Location: <a href="http://www.newdomain.com/directory/"" title="http://www.newdomain.com/directory/"">http://www.newdomain.com/directory/"</a>);
?>

Change the URL in blue to the URL of your choice.

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

Umm just to revive this thread again,

In request.php I have the following:

<?php
header
(\"Location:$_REQUEST['url']\");
?>

And in index.php I have this line of coding :

<?php
<p class=\"text\">The new site can be found here: <a href=\"request.php?url=http://impactdesignz.webpros.co.nz/nethelp\" class=\"link\">Here</a></p>
?>

What have I done wrong? It comes up with this error when the link is clicked on :

Quote:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\phpdev\www\public\nethelp\request.php on line 2

dk01's picture

He has: 516 posts

Joined: Mar 2002

Anyone correct me on this one but wouldn't you use:

<?php
header
(\"Location: $_GET['url']\");
?>

or
<?php
header
(\"Location: $url\");
?>

Make sure you have a space in between Location: and the url.
-dk

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.