NYCPHP Meetup

NYPHP.org

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

Dell Sala dell at sala.ca
Fri Dec 15 18:57:01 EST 2006


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.

-- 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?




More information about the talk mailing list