Forum Moderators: coopster

Message Too Old, No Replies

What's the best way to "re-write" a dynamic page?

Using re-write to make everything more friendly for linking and SE's...

         

ncreegan

5:43 pm on May 24, 2004 (gmt 0)

10+ Year Member



Here's my situation. I have a database filled with specs on about just about every car ever produced, but I'm not pleased with the page.php?car_id=1223, and neither is G. I've been searching through some mod-rewrite but I'm still a little confused as to the proper format to use.

I want to go from something like page.php?car_id=1223 to /make/duesenberg/model/1934-dual-cowl-phaeton/page.php (or whatever they best format is, especially for dealing with spaces.)

Thanks!

hughie

8:06 pm on May 24, 2004 (gmt 0)

10+ Year Member



For a big site like that it might be worth generating a page from a template(similar to your current page.php) with a name such as Car_Title_UniqueID.php

The uniqueID at the end of the file name will stop clashes with simlar named pages.

In your database you have the fields

UniqueID ,Car_Title, Page_Name, etc

Page_Name being automatically generated from the the first 2 columns.

When you retrieve the information from the database instead of it coming out like
page.php?id=232

it comes out as
Car_Title_UniqueID.php

When that page loads you then need to do a check into the database for the entry with Page_Name=The current file name. You then store the ID of that entry as a Session or Global variable and use it as if it had been entered as a GET variable.

hope that makes sense,
Hughie

ncreegan

10:24 pm on May 24, 2004 (gmt 0)

10+ Year Member



Thanks I was thinking that too but though that would work for that certain example, there are other places on the site where I really need the slash style rewriting.

hughie

8:43 am on May 25, 2004 (gmt 0)

10+ Year Member



not sure on that, maybe someone can fill us both in ;-)

ta,
hughie

cfinlay

5:41 pm on May 25, 2004 (gmt 0)

10+ Year Member



ncreegan,

Having just done something along the lines of mod_rewrite, your problem is easily solved by just rewriting the id to /id/####.

If you're looking to provide all that information in the string though, you'll have to adjust the data presented to the script. If you have the data available on previous pages to supply the link for '/make/duesenberg/model/1934-dual-cowl-phaeton/page.php', and your destination script can take the information, go that route..

But, if all you have is an car_id variable and everything is specialized for that, the way of lesser headaches is going through /car/id/#####.

I hope this helps. I'm not sure if mod_rewrite can do queries on its own to find your desired ID. Then again, you could always write a php to do a lookup for the given car information, assign the id, then include the php that presents the information..

-C