[nycphp-talk] Howto create custom URLs
Ben Sgro (ProjectSkyline)
ben at projectskyline.com
Mon Mar 26 18:58:58 EDT 2007
Hello yall,
I decided to just do the wrapper because it was quick and painless...
Here's a snippet from the new event.php file.
------------------------------------------------
/* This is our wannabe mod_rewrite hack
The REQUEST_URI comes in as /pc_release/event.php/myEvent
we only want the myEvent value.
*/
$eventNameStr = strrchr($_SERVER['REQUEST_URI'], "/");
$eventNameStr = substr($eventNameStr, 1, strlen($eventNameStr));
DBAS_InitDBHandle(HHCE_SQLInfo( ), 'HHCE.php', $db);
$tName = constEventLookupStr;
$sqlStr = "SELECT event_id FROM $tName WHERE event_name = '$eventNameStr'";
DBAS_MySQLReturnOne($eventSet, $sqlStr, $db);
$eventId = $eventSet['event_id'];
$host = $_SERVER['HTTP_HOST'] . "/pc_release/index.php?act=700&eventid="
. $eventId;
/* REDIRECT */
header("Location: http://$host");
------------------------------------------------
/event.php/MyEvent =(redirects to)> /index.php?act=....
Works fine and I only had to make minimal changes to my existing code.
Thanks for all the great ideas everyone!
- Ben
----- Original Message -----
From: Jiju Thomas Mathew
To: NYPHP Talk
Sent: Monday, March 26, 2007 1:49 PM
Subject: Re: [nycphp-talk] Howto create custom URLs
regex replace, right? What about urls that are constructed
dynamically in javascript? And I feel there must be other holes. Is
there a way this can be done reliably, or am I just being paranoid?
Actually you would either redesign the package, such that you wont mess up with
htaccess, mod_rewrite or any such sort of plugs, or use some kind of internal plugs
which will always be a headache.
I was involved in a project where the web server was really a modest one with
256MB ram and a pIII 800 processor yet, had a very huge database, but the basic
thing is that the data seldom changes, ie, there may be additions, but modifications
are not that frequent.
We had the folowing htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^projects/(.*)\.html projects.php?g=$1 [L]
we also had a projects folder which was writable by the webserver process. now
the php script would get the $_GET['g'], which could be parsed to identify which
section of the projects was being referred to, and the database content would be
merged with the static and layout template, and finally the whole html page is built
into one single varaible, which is written to 'projects/' . $_GET['g'] . '.html', as well
as echoed. So in a second request, the file will be fetched from the file system.
Whenever the content in a particular section is modified, we just unlink the related
html file, which will get generated in the first subsequent request.
The point which I wanted to emphasise is that you should consider redoing the whole
package with the furl in mind, and you will start seeing that you will no longer require
any plugs.
--
Jiju Thomas Mathew
http://www.php-trivandrum.org
------------------------------------------------------------------------------
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk
NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com
Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20070326/67f3467c/attachment.html>
More information about the talk
mailing list