NYCPHP Meetup

NYPHP.org

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

Rob Marscher rmarscher at beaffinitive.com
Tue Oct 3 12:49:34 EDT 2006


Yeah, Cliff.  If all of your pages already follow a standard of 
?page=somepage&action=someaction&other params...

Then you can just drop in this rule:
RewriteRule (.+)/(.+) index.php?page=$1&action=$2 [QSA,L]

And instantly be able to do 
www.somesite.com/sompage/someaction?otherparam=something&etc...
without breaking anything.  You wouldn't even have to change any of your 
existing links immediately if you didn't feel like it... they would 
still work.

-Rob

Cliff Hirsch wrote:
> 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
>
> _______________________________________________
> 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