Redirect, but keep uri the same

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Redirect, but keep uri the same

Post by Luke »

Is there any way WITHIN PHP or with headers to redirect somebody to a new location, but keep the URI the same (in the URL)?
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

Code: Select all

<?php
header('Location: http://www.newlocation.com' . $_SERVER['REQUEST_URI']);
?>
Last edited by WaldoMonster on Tue Feb 20, 2007 7:42 pm, edited 1 time in total.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

wouldn't that just redirect me to the same page I'm on? I need to redirect to a new location.
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

The Ninja Space Goat wrote:wouldn't that just redirect me to the same page I'm on? I need to redirect to a new location.
if run form: http://www.oldsite.com/something/index.php
it will redirect to: http://www.newlocation.com/something/index.php

If this is not what you want, please give an example.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

You want to cloak the URL? You could include() the URL you're redirecting to, but that seems sloppy to me.

Why not mod_rewrite?
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

write a function on mod-rewrite of apache using php
Post Reply