NYCPHP Meetup

NYPHP.org

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

Kenneth Downs ken at secdat.com
Sat Dec 16 09:04:14 EST 2006


Greg and Dell,

Problem Solved!

Thanks very much for the idea, and also for the detailed explanation.  
Problem is now solved and I know a little more about Apache than I did 
yesterday.
> On 12/15/06, Kenneth Downs <ken at secdat.com> 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.
>
> Ken, I think you're missing a fine point in Dell's explanation.  To be
> explicit, the reason Dell's solution works is because Apache works it
> way down the request path (moving from left to right) until it finds
> something it can return.  Apache does not look at the URI and work
> it's way "backward".  So, if you have a script||directory||symbolic
> link named 'jukebox' accessible at http://mysite.org/jukebox/ then
> Apache will serve it up even if the request is for
> http://mysite.org/jukebox/clapton/heaven.mp3.  Of course not only will
> Apache serve up the 'jukebox' script, but since it's a mod-PHP script,
> it is well aware of the full $_SERVER['REQUEST_URI'] which the script
> can use to determine what exactly to do with the request.... like go
> get a song from the database.
>
>> > your php script would be
>> >
>> > http://domain.com/mp3handler
>> >
>> > and full requests would look like this
>> >
>> > http://domain.com/mp3handler/music.mp3
>> >
>> > mp3handler would just parse the full request string to find out what
>> > mp3 was requested
>> >
>> > your .htaccess file would be something like this:
>> >
>> > <FilesMatch "^mp3hanlder$">
>> >    ForceType application/x-httpd-php
>> > </FilesMatch>
>> >
>> > I've found this to be an effective technique for creating clean urls.
>>
>> 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?
>>
>> >
>> > -- Dell
>> >
>> >
>> > On Dec 15, 2006, at 5:35 PM, Kenneth Downs wrote:
>> >
>> >> I'm guessing that this must be a common trick, but googling it did
>> >> not come up with an example that I could figure out.
>> >>
>> >> Basically I'd like to put a link to what looks like an MP3 file, but
>> >> which is redirected to a script.  The script determines if the person
>> >> is subscribed to that particular issue. If they are, it does a
>> >> readfile(), otherwise it does not.
>> >>
>> >> I cannot do a simple force of mp3 files to be handled by PHP, or at
>> >> least I don't want to, because then I would need a file for every
>> >> mp3, and as the list comes out of a database, this would be 
>> troublesome.
>> >>
>> >> The basic problem I have is, not being familiar with mod_rewrite, I
>> >> find myself in the endless maze that everybody warns you about,
>> >> fiddling around and smashing fists on the table wondering why the
>> >> simplest !)(#(*#@ expression won't work.
>> >>
>> >> What I'm looking for is for a URL like this:
>> >>
>> >> http://www.example.com/path/path/somefile.mp3
>> >>
>> >> to become:
>> >>
>> >> 
>> http://www.example.com/path/path/index.php?gp_page=media&file=somefile.mp3 
>>
>> >>
>> >>
>> >> Can anybody give me a clue here?  Thanks.
>> >> <ken.vcf>
>> >> _______________________________________________
>> >> 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
>>
>>
>>
>> _______________________________________________
>> 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: 273 bytes
Desc: not available
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20061216/ae91363d/attachment.vcf>


More information about the talk mailing list