Forum Moderators: phranque

Message Too Old, No Replies

How to translate SE friend URL

read data from URL like /category/itemid/color

         

phparion

11:05 am on Oct 4, 2006 (gmt 0)

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



hi

i have seen on many sites people use URLs like

www.domain.com/category/itemid/color

and then they somehow translate it to read data from database.

e.g this URL www.domain.com/category/index.php?itemid=10&color=red may look like

www.domain.com/category/10/red

now please help me to find the answers to the following questions

1 - how to make hyperlink for such URLs? for example if i do something like

<a href="/category/10/red" > link </a>

then it will show me HTTP 404 error as it will read '10' and 'red' as folders ...

2 - how to fetch needed data from the URL like www.domain.com/category/10/red and store in variables to use in dynamic queries.

please reply..
thanks

lmo4103

12:23 pm on Oct 4, 2006 (gmt 0)

10+ Year Member



e.g this URL www.domain.com/category/index.php?itemid=10&color=red may look like

www.domain.com/category/10/red

If it looks instead like www.domain.com/category/index.php/10/red
then apache is capable of recognizing that "index.php" is a php program.
If so, then $_SERVER['PATH_INFO'] would contain /10/red

You could do: list($scrap, $itemid, $color) = spliti("/", $_SERVER['PATH_INFO']);

($scrap is to catch the null string before the first delimiter "/".)

I have not found 'PATH_INFO" documented in the php manual and am curious why php never documented it.
I had one occasion when 'PATH_INFO' was not configured to work on some server but I don't know how that was addressed and fixed. If anyone knows about this configuration, I would be interested.

[edited by: lmo4103 at 12:50 pm (utc) on Oct. 4, 2006]

lmo4103

12:33 pm on Oct 4, 2006 (gmt 0)

10+ Year Member



You could make urls like: <a href="/category/index.php/10/red" > link </a>
or use mod_rewrite. Search "dynamic url" had lots of results on webmasterworld.

jdMorgan

5:07 pm on Oct 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See Changing dynamic to static URLs [webmasterworld.com] - A basic introduction to using mod_rewrite on Apache server to implement search-engine-friendly static URLs on dynamically-generated sites, located in our Apache forum library.

This can be combined, to a greater or lesser degree depending on your preference, with the method described above by lmo4103.

Jim