NYCPHP Meetup

NYPHP.org

[nycphp-talk] mod_rewrite -- what's the big deal?

Cliff Hirsch cliff at pinestream.com
Tue Oct 3 10:12:34 EDT 2006


Ok, so I'm starting to see the benefits, but now I have to be an Apache
guru on top of a PHP guru? Can anyone suggest good tutorials?

Does this mean I have to change every URL that's embedded in every page
from ?key=value&... to /value1/value2 And do I have to know the order of
the request params for it to work? Or as Chris says, do I still access
the query values from $get, $post?

I don't use a Framework or a true MVC architecture -- I think. It's more
like Cliff's hack. But to my defense, I do use a single entry point
(index.php) that dispatches requests via
?page=somepage&action=someaction&other params as required.

So where would I go from here? And don't say scrap your code and switch
to a Framework.

-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org]
On Behalf Of csnyder
Sent: Tuesday, October 03, 2006 8:44 AM
To: NYPHP Talk
Subject: Re: [nycphp-talk] mod_rewrite -- what's the big deal?

On 10/3/06, Cliff Hirsch <cliff at pinestream.com> wrote:

> What difference does it make? To me it mainly looks like a major
headache
> making all the queries written in PHP play nicely with mod_rewrite.

This may be going beyond the substance of your question, but
mod_rewrite is arguably the best way to enable a
model-view-controller-ish interface for your web application. A simple
rewrite rule, along with some exceptions for static assets (design
elements, javascript libraries), will funnel everything through your
dispatch script.

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/www/.*
RewriteRule ^.* /usr/local/myframework/http-engine.php

Now all requests that don't begin with /www/ get handled by one
script, which can give you big savings in the maintenance and security
departments.

Rewriting doesn't change queries at all, btw. You can pick up the
requested uri from the $_SERVER superglobal, and $_GET vars are set
correctly.

---
Chris Snyder
http://chxo.com/
_______________________________________________
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




More information about the talk mailing list