dslreports logo
site
    All Forums Hot Topics Gallery
spc
Search Topic:
uniqs
1031
share rss forum feed


theedj
Right Back At-Cha
Premium
join:2002-12-12
Calgary

Redirect with additional variables

I'm not sure if this makes sense as a PHP script or something more root level like a mod_rewrite. I have a need to create some friendly links from one site to another.

Essentially I have site.com/blah that needs to forward to siteb.com/blah?s=stuff

The 'blah' will be different but the origin and destination URL's will be the same, as well as appending the ?s=stuff though potentially if there are already variables in the string, this would need to be appended with &s=stuff to ensure the string functions correctly.

I'm hoping I can lean back on my tried and tested resources here...though it's been a long time since I've posted something.

The other thing, I don't want to have to create each forward. I know I could use something like Pretty Links in Wordpress, but that's overkill for something so simple.

Thanks in advance.

//Marshall
--
Wanna be in a movie?
#1 spot for Winnipeg Jets news, rumors & reads
I'm going on a road trip!



theedj
Right Back At-Cha
Premium
join:2002-12-12
Calgary

Seriously? I'm shocked there's nothing on this yet.

What I'm thinking of doing is utilizing some PHP to simply grab the URL, the trim the string, add the code and set the header...it's just been so long since I've done anything PHP.

The question really comes down to the 'any URL' aspect as I don't want to have to create the file for each redirect I want to make. Any help in that area would be appreciated.

Thanks

//Marshall
--
I talk about the Winnipeg Jets
#1 spot for Winnipeg Jets news, rumors & reads
I like to drink beer & talk hockey



Tenar

join:2008-01-02
Midland, ON
reply to theedj

are these URLs that already exist?

If no you could put your php script into a custom 404 page. Then you can parse out the URL and do the redirect.



Toad

join:2001-07-22
Bradford, ON
kudos:1
reply to theedj

You should be able to accomplish this with conditional mod_rewrites or with a php page that creates a meta refresh based on the parameters.
--
»www.toddsplace.ca



cowboyro
Premium
join:2000-10-11
Shelton, CT
Reviews:
·AT&T U-Verse
reply to theedj

Why not use the KIS approach?

<?php
$requestURI = $_SERVER["REQUEST_URI"];
if(strpos($requestURI,'?')===false)
  $requestURI = $requestURI."?";
else
  $requestURI = $requestURI."&";
 
 $requestURI = $requestURI."s=stuff";
 header( 'Location: http://siteb.com'.$requestURI ) ;
?>
 


cdru
Go Colts
Premium,MVM
join:2003-05-14
Fort Wayne, IN
kudos:7

said by cowboyro:

Why not use the KIS approach?

Because mod_rewrite can accomplish the same thing in fewer lines without having to run it through PHP.


cowboyro
Premium
join:2000-10-11
Shelton, CT
Reviews:
·AT&T U-Verse

said by cdru:

said by cowboyro:

Why not use the KIS approach?

Because mod_rewrite can accomplish the same thing in fewer lines without having to run it through PHP.

If number of lines is an issue then squeeze it to one line:
<?php header( "Location: http://siteb.com". $_SERVER["REQUEST_URI"] . (strpos($_SERVER["REQUEST_URI"],'?')===false,"?","&") . "s=stuff") ?> ;
 
However it offers more granular control on how the redirect will be done and can be ported directly to different platforms (say IIS) or even to a different host that may not have mod_rewrite enabled.