Forum Moderators: coopster

Message Too Old, No Replies

adding parameter to url's

add parameter to urls

         

frogz

11:40 am on Jan 3, 2009 (gmt 0)

10+ Year Member



hello!

I have php pages that urls started like: /album.php?user=455
I have htaccess rewritten & redirected them to: /mypics-455.htm
now, in the script I added extra variables to the internal urls to produce: /mypics-455-frogz.htm , The htaccess rewrite and everything is fine, but, "-frogz" is only served up in the url when an internal link is requested. Therefore, when a search engine requests the old link: album.php?user=455 , i cannot get it to redirect to:/mypics-455-frogz.htm, only:/mypics-455-.htm (name is missing)
How can I get the page requested to parse the url and add "$" when necessary?

function daPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

Mahabub

12:22 pm on Jan 3, 2009 (gmt 0)

10+ Year Member



frogz,

you can get the page requested by the below variable.

$_SERVER["REQUEST_URI"]

Thanks
Mahabub

frogz

1:46 pm on Jan 3, 2009 (gmt 0)

10+ Year Member



thanks Muhabub,

i need to make sure $_SERVER["REQUEST_URI"] has a variable in it before passed to the browser. there a way I can force a suffix to each page? so page /album-user-4.html returns: /album-user-4<added $$$$$>.html
in each page? something like:

$_SERVER["REQUEST_URI"]."added suffix";

my apologies for not being clear enough.
thnx in advance.

frogz

1:56 pm on Jan 3, 2009 (gmt 0)

10+ Year Member



i thought about: str_replace(blahblah, "blahblah-bleet_bleet", $newurl->page, $count);
but this would give me an infinite loop

eelixduppy

2:33 pm on Jan 3, 2009 (gmt 0)



Why wouldn't you add this suffix to your rewrite in .htaccess? Seems like the way I'd go.

frogz

5:28 pm on Jan 3, 2009 (gmt 0)

10+ Year Member



I would, but htaccess does'nt process queries, in which i need. The added "suffix" will be a variable:
$_SERVER["REQUEST_URI"]."-".$userid;

the page requested looks like: /album.php?userid=44
I have mod_rewrite rewriting the url to: /album-44.htm
I added extra parameters to the internal links that now when clicked will look like: /album-44-frogz.htm

<a href="album-$num-$id.htm"></a>

all works great internally, but the search engines already have /album-44.htm indexed. i need to 301 them to the new URL (with -$id).
(i cant add -$id to htaccess i dont think)
Thats why i was thinking I could use $_SERVER["REQUEST_URI"] and add the extra parameter before its passed to the browser.

thanx for all your help.

frogz

3:37 am on Jan 4, 2009 (gmt 0)

10+ Year Member



tee he that was easy, I just flagged the url I needed changed, redirected the flagged url to another page where the variable was then loaded into the url, then directed to the htaccess static page.

thanx for your suggestions!

g1smd

7:52 pm on Jan 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use HTTP Live Headers to examine how many redirects the browser "sees" when requesting that type of URL.

You should get to start to finish in just one hop. That is, multiple hops - a redirection chain - should always be avoided.

Check with both www and non-www inputs. All should result in just one hop, not a chain.

frogz

10:21 pm on Jan 8, 2009 (gmt 0)

10+ Year Member



very good to know g1smd, ty! :)