Forum Moderators: phranque

Message Too Old, No Replies

CMS and url rewriting and page id's

Am thinking about reprogramming my CMS

         

louponne

10:38 pm on Mar 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello everyone,

I have built a small CMS that has two database tables: one for pages and one for items of content.

The relation among the pages of the site is built on a recursive relationship between the pages, so the entire architecture is produced by two fields of data in the "pages" table - id_page and id_parent. The id is always a text.

It works great but I have urls that have the end with something like page.php?id=mypage - not great for SEO and limited, because no two pages can have the same id.

So I'm thinking of doing url rewriting and changing my page id's so that they are house$firstfloor$livingroom which would correspond to the page with the public url of house/firstfloor/livingroom

This would mean that I wouldn't need to do my recursive thing to create the site structure because it would all be in the id - all I'd need to do is break into pieces and the CMS will "know" where that page belongs.

I'm really hesitating about this because I'm no big coder and it will mean many days of work - does anyone have any comments, pro or con, on what I have planned?

Thanks to anyone who reads this!

linear

2:47 pm on Mar 28, 2006 (gmt 0)

10+ Year Member



Here's one way to do this in PHP


$q = $_SERVER["REQUEST_URI"];
$script = $_SERVER["SCRIPT_NAME"];
$q = ereg_replace("^$script", "", $q);
$args = explode ("/" ,$q);

At this point, you have an array $args whose elements contain the stuff in the request URI. Under Apache 2 you have to explicitly enable this script to accept path info (with the AcceptPathInfo directive [httpd.apache.org]).

So if you code pages.php to handle arguments this way, your example of pages.php?id=mypage can become pages.php/mypage

You're going to want to validate the input and catch exceptions--don't assume that any user input is valid (but your existing script does all kinds of checking on $id before submitting it to the db, right?)