Forum Moderators: coopster

Message Too Old, No Replies

Can't grab the URL, after changing it with .htaccess

i'm stumped

         

londrum

10:05 pm on Mar 22, 2009 (gmt 0)

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



hello. just wondering if someone knows a way around a little thing that is tearing my hair out.

i have a blog which splits posts up into categories. and i write certain stuff onto the page depending on which category it is.
i do this by looking at the query string on the end of the URL.

but now i have discovered the wonderful permalinks thing in wordpress, and want to use it. so all my query strings have disappeared. and they are rewritten with the .htaccess file.

so whereas it might have been
www.example.com/category.php?no=6

now it is
www.example.com/category/no/6

but now i can't grab the url. no matter what i have tried in PHP, the best i can get is category.php. i can't grab the original query string that was on the end, nor the new /no/6 bit.

so i have no easy way of php checking which category the post is in.

does anyone know how you can grab the /no/6 bit in PHP?

topr8

10:23 pm on Mar 22, 2009 (gmt 0)

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



htaccess is redirecting
www.example.com/category/no/6
internally to
www.example.com/category.php?no=6

so although the browser address bar says
www.example.com/category/no/6

you are actually serving page:
www.example.com/category.php?no=6

so you should be able to get the '6' by requesting a querystring in the normal way eg

$value=$_GET["no"];

londrum

10:27 pm on Mar 22, 2009 (gmt 0)

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



that is how i thought it would be too, but a simple
echo $_SERVER['QUERY_STRING'] returns nothing at all

if i turn the .htaccess stuff off and try again, then it works as expected

coopster

10:35 pm on Mar 22, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



does anyone know how you can grab the /no/6 bit in PHP?

Dump the entire $_SERVER variable. Run this at the top of your script to see what you have available. Typically, I believe the PATHINFO is where you should always see it, but the REQUEST_URI is what I tend to use most often.

<?php 
print '<pre>';
print_r($_SERVER);
print '</pre>';
exit;
?>

londrum

7:52 pm on Mar 23, 2009 (gmt 0)

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



i don't know you could even get a page up like that with all that stuff on. it was worth having the problem just to find that out.

looks like the REQUEST_URI will do the trick, cheers

coopster

10:17 am on Mar 24, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hehe, well, that little superglobals trick [webmasterworld.com] is in the PHP Forum Library [webmasterworld.com] where you will find many more.