NYCPHP Meetup

NYPHP.org

[nycphp-talk] Help with a basic mod_rewrite issue?

Kenneth Downs ken at secdat.com
Sat Dec 16 09:26:07 EST 2006


Dell Sala wrote:
> I think this is exactly what you're looking for.
>
> mp3handler is a php script, just named without a ".php" extension.
>
> if you force apache to treat mp3handler as a php script, you can 
> create urls that access mp3handler, but appear to to be accessing a 
> more deeply nested file or resource.
>
> a request like http://domain.com/mp3handler/somefile.mp3 will cause 
> apache to execute the mp3handler script, and the rest of the request 
> is just ignored by apache. Then, inside mp3hanlder you can manually 
> parse $_SERVER['PATH_INFO'] to retrieve your "argument" which is 
> /somefile.mp3.
>
> I started using this technique after seeing it in a great article in 
> PHP|Architect. Volume 5, Issue 3 "Frameworks: what's the big deal" by 
> Darryl Patterson.
>

Aha, so then this also provides a way to use the universal dispatch 
method and "friendly" URLs without resorting to mod_rewrite.  I can 
create a script called "pages" and invoke it like so:

<FilesMatch "^pages$">
  ForceType application/x-httpd-php
</FilesMatch>

...and then generate URLs like so:

http://www.example.com/pages/pagename/parm/value/parm/value

and then just parse out the URI into parm-value pairs.

Nice!


> -- Dell
>
>
> On Dec 15, 2006, at 6:24 PM, Kenneth Downs wrote:
>
>> Dell Sala wrote:
>>> mod_rewrite seems like a messy business. How about naming your php 
>>> script without a .php extension and just have that be parsed with 
>>> php? Then, whatever path is appending to the script name that is 
>>> requested just acts as a query string/argument.
>>
>> This looks interesting, can you give me some details here:
>>
>> 1)  The intent is to redirect to music.mp3, which is actually a php 
>> script, right?
>> 2)  But then the rule is on "mp3handler", which is constant so it 
>> can't be a parameter?
>> 3)  So what is the parameter?  How do I tell a single script to 
>> handle multiple files?
>>
>> What I'm aiming at is to have a single script that takes a parm.  If 
>> I understand your example above, it requires a separate script for 
>> each possible mp3 file, which may as well just be this:
>>
>> <FilesMatch "\.mp3$">
>>   ForceType application/x-httpd-php
>> </FilesMatch>
>>
>> ...which requires me again to have one script per mp3.
>>
>> Am I missing something?
>
> _______________________________________________
> 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 --------------
A non-text attachment was scrubbed...
Name: ken.vcf
Type: text/x-vcard
Size: 261 bytes
Desc: not available
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20061216/b3f2c214/attachment.vcf>


More information about the talk mailing list