ReWrite Rule Question

This is a discussion on ReWrite Rule Question within the Apache Web Server forums, part of the Web Server and Related Forums category; I have a director structure as follows: public_html audio public_html of course is the web directory. I have audio files ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-02-2006
Brian Huether
 
Posts: n/a
Default ReWrite Rule Question

I have a director structure as follows:

public_html
audio

public_html of course is the web directory. I have audio files in audio.
They are streamed to a user by a script underpublic_html called audio.php.
So the urls that are used are of the form

audio.php?op=serveaudio&file=..audio/file.mp3

I would like to use a ReWrite rule to do the following: A url of the form
audiostuff/file.mp3 gets rewritten to

audio.php?op=serveaudio&file=..audio/file.mp3

Of course file will be an arbitrary name and so the rewrite rule has to use
wildcards or something so that any file gets rewritten properly. How would I
do this?

thanks,

brian


  #2 (permalink)  
Old 12-02-2006
HansH
 
Posts: n/a
Default Re: ReWrite Rule Question

"Brian Huether" <bhuetherNO@comcastSPAM.net> schreef in bericht
news:D6ednVUGG5NUHuzYnZ2dnUVZ_r2dnZ2d@comcast.com. ..
> So the urls that are used are of the form
> audio.php?op=serveaudio&file=..audio/file.mp3
> I would like to use a ReWrite rule to do the following: A url of the form
> audiostuff/file.mp3 gets rewritten to
> audio.php?op=serveaudio&file=..audio/file.mp3
>

Test for me within ./audiostuff/.htaccess
RewriteBase \
RewriteRule (.*\.mp3)$ audio.php?op=serveaudio&file=../audio/$1

or within ./.htaccess
RewriteRule ^[^/]+/(.*\.mp3)$ audio.php?op=serveaudio&file=../audio/$1

The latter is prone to cause reduced performance.

HansH


  #3 (permalink)  
Old 12-02-2006
Brian Huether
 
Posts: n/a
Default Re: ReWrite Rule Question


"HansH" <hansh@invalid.invalid> wrote in message
news:45718e68$0$331$e4fe514c@news.xs4all.nl...
> "Brian Huether" <bhuetherNO@comcastSPAM.net> schreef in bericht
> news:D6ednVUGG5NUHuzYnZ2dnUVZ_r2dnZ2d@comcast.com. ..
>> So the urls that are used are of the form
>> audio.php?op=serveaudio&file=..audio/file.mp3
>> I would like to use a ReWrite rule to do the following: A url of the form
>> audiostuff/file.mp3 gets rewritten to
>> audio.php?op=serveaudio&file=..audio/file.mp3
>>

> Test for me within ./audiostuff/.htaccess
> RewriteBase \
> RewriteRule (.*\.mp3)$ audio.php?op=serveaudio&file=../audio/$1
>
> or within ./.htaccess
> RewriteRule ^[^/]+/(.*\.mp3)$ audio.php?op=serveaudio&file=../audio/$1
>
> The latter is prone to cause reduced performance.
>
> HansH
>


audiostuff is actually a bogus directory

the real directory is audio and it is at same level as public_html

thanks,

brian


  #4 (permalink)  
Old 12-02-2006
HansH
 
Posts: n/a
Default Re: ReWrite Rule Question

"Brian Huether" <bhuetherNO@comcastSPAM.net> schreef in bericht
news:4ZadnThwlreBB-zYnZ2dnUVZ_oqdnZ2d@comcast.com...
>>> So the urls that are used are of the form
>>> audio.php?op=serveaudio&file=..audio/file.mp3
>>> I would like to use a ReWrite rule to do the following: A url of the
>>> form audiostuff/file.mp3 gets rewritten to
>>> audio.php?op=serveaudio&file=..audio/file.mp3
>>>

>> or within ./.htaccess
>> RewriteRule ^[^/]+/(.*\.mp3)$ audio.php?op=serveaudio&file=../audio/$1
>>

> audiostuff is actually a bogus directory

That's why I reluctantly -performance penalty- gave a rule for ./.htaccess
replacing the firts foldername by '../audio'
>
> the real directory is audio and it is at same level as public_html

From your previous post I assumed public_html to be your document root and
to have the same parent folder as audio. -Rather unsuprising given some
suggestions in your other thread about mp3-
Document root is then assummed -unsure though- to be the current working
directory for audio.php. Alltogether that's why the file parameter starts
.../audio.

Still I do think, though did not test,
RewriteRule ^[^/]+/(.*\.mp3)$
audio.php?op=serveaudio&file=%{DOCUMENT_ROOT}/../audio/$1
will handle a request like
/whatever/classic/mozart/5thsymphony.mp3
to stream
/audio/classic/mozart/5thsymphony.mp3


HansH


  #5 (permalink)  
Old 12-02-2006
Brian Huether
 
Posts: n/a
Default Re: ReWrite Rule Question


"HansH" <hansh@invalid.invalid> wrote in message
news:4571aa01$0$335$e4fe514c@news.xs4all.nl...
> "Brian Huether" <bhuetherNO@comcastSPAM.net> schreef in bericht
> news:4ZadnThwlreBB-zYnZ2dnUVZ_oqdnZ2d@comcast.com...
>>>> So the urls that are used are of the form
>>>> audio.php?op=serveaudio&file=..audio/file.mp3
>>>> I would like to use a ReWrite rule to do the following: A url of the
>>>> form audiostuff/file.mp3 gets rewritten to
>>>> audio.php?op=serveaudio&file=..audio/file.mp3
>>>>
>>> or within ./.htaccess
>>> RewriteRule ^[^/]+/(.*\.mp3)$ audio.php?op=serveaudio&file=../audio/$1
>>>

>> audiostuff is actually a bogus directory

> That's why I reluctantly -performance penalty- gave a rule for ./.htaccess
> replacing the firts foldername by '../audio'
>>
>> the real directory is audio and it is at same level as public_html

> From your previous post I assumed public_html to be your document root and
> to have the same parent folder as audio. -Rather unsuprising given some
> suggestions in your other thread about mp3-
> Document root is then assummed -unsure though- to be the current working
> directory for audio.php. Alltogether that's why the file parameter starts
> ../audio.
>
> Still I do think, though did not test,
> RewriteRule ^[^/]+/(.*\.mp3)$
> audio.php?op=serveaudio&file=%{DOCUMENT_ROOT}/../audio/$1
> will handle a request like
> /whatever/classic/mozart/5thsymphony.mp3
> to stream
> /audio/classic/mozart/5thsymphony.mp3
>
>
> HansH
>


I am having strange behavior. These urls should produce equivalent results:

http://www.mysite.com/audio.php?op=s...&file=file.mp3

http://www.mysite.com/audiostuff/file.mp3

The php code that processes this is

$op = $_REQUEST["op"];
$file = $_REQUEST["file"];

serveaudio($file);

function serveaudio($file) {

$link = "./audio/".$file;

//echo $link;
//die();

header("Location: " .$link);

}

When I echo the link, they are identical. The first url will cause the audio
to stream and the second gets me a 403 forbidden error and also the url line
in the browser gets replaced with

http://www.mysite.com/audiostuff/aud...audio/file.mp3


On the one hand it seems to rewrite isn't working, but if that is the case,
then why are both url's causing the same behavior in the serveaudio script?

Anyway, I have experiemented with trying to have the audio folder above the
web root but now I just want to have it under the web root. So right now my
current directory structure is

home
public_html (webroot)
audio

thanks,

brian


  #6 (permalink)  
Old 12-02-2006
HansH
 
Posts: n/a
Default Re: ReWrite Rule Question

"Brian Huether" <bhuetherNO@comcastSPAM.net> schreef in bericht
news:9J-dnVqtzaojL-zYnZ2dnUVZ_h6dnZ2d@comcast.com...
>> Still I do think, though did not test,
>> RewriteRule ^[^/]+/(.*\.mp3)$
>> audio.php?op=serveaudio&file=%{DOCUMENT_ROOT}/../audio/$1
>> will handle a request like
>> /whatever/classic/mozart/5thsymphony.mp3
>> to stream
>> /audio/classic/mozart/5thsymphony.mp3

>
> I am having strange behavior. These urls should produce equivalent
> results:
> http://www.mysite.com/audio.php?op=s...&file=file.mp3
> http://www.mysite.com/audiostuff/file.mp3
>
> The php code that processes this is
> $op = $_REQUEST["op"];
> $file = $_REQUEST["file"];
> serveaudio($file);
> function serveaudio($file) {
> $link = "./audio/".$file;

The rewriterule given already provides the full local path[, I think]

> //echo $link;
> //die();
>
> header("Location: " .$link);

That's NOT streaming, that is redirecting ...
.... take this [and more] advise ginven in the other thread:
< header("Content-Type: audio/x-mpeg");
< echo @file_get_contents($file);

>
> }
>
> When I echo the link, they are identical. The first url will cause the
> audio to stream and the second gets me a 403 forbidden error and also the
> url line in the browser gets replaced with

.... replaced url, indeed your are redirecting ...
> http://www.mysite.com/audiostuff/aud...audio/file.mp3

.... into endless circles
>
> current directory structure is
>
> home
> public_html (webroot)
> audio

Your choice, not mine -discurraged by others too-
Have the rewrite your way
RewriteRule ^[^/]+/(.*\.mp3)$
audio.php?op=serveaudio&file=%{DOCUMENT_ROOT}/audio/$1

and don't forget the 'deny from all' ao in /audio/.htaccess


HansH


  #7 (permalink)  
Old 12-02-2006
Brian Huether
 
Posts: n/a
Default Re: ReWrite Rule Question


"HansH" <hansh@invalid.invalid> wrote in message
news:4571c22c$0$324$e4fe514c@news.xs4all.nl...
> "Brian Huether" <bhuetherNO@comcastSPAM.net> schreef in bericht
> news:9J-dnVqtzaojL-zYnZ2dnUVZ_h6dnZ2d@comcast.com...
>>> Still I do think, though did not test,
>>> RewriteRule ^[^/]+/(.*\.mp3)$
>>> audio.php?op=serveaudio&file=%{DOCUMENT_ROOT}/../audio/$1
>>> will handle a request like
>>> /whatever/classic/mozart/5thsymphony.mp3
>>> to stream
>>> /audio/classic/mozart/5thsymphony.mp3

>>
>> I am having strange behavior. These urls should produce equivalent
>> results:
>> http://www.mysite.com/audio.php?op=s...&file=file.mp3
>> http://www.mysite.com/audiostuff/file.mp3
>>
>> The php code that processes this is
>> $op = $_REQUEST["op"];
>> $file = $_REQUEST["file"];
>> serveaudio($file);
>> function serveaudio($file) {
>> $link = "./audio/".$file;

> The rewriterule given already provides the full local path[, I think]
>
>> //echo $link;
>> //die();
>>
>> header("Location: " .$link);

> That's NOT streaming, that is redirecting ...
> ... take this [and more] advise ginven in the other thread:
> < header("Content-Type: audio/x-mpeg");
> < echo @file_get_contents($file);
>
>>
>> }
>>
>> When I echo the link, they are identical. The first url will cause the
>> audio to stream and the second gets me a 403 forbidden error and also the
>> url line in the browser gets replaced with

> ... replaced url, indeed your are redirecting ...
>> http://www.mysite.com/audiostuff/aud...audio/file.mp3

> ... into endless circles
>>
>> current directory structure is
>>
>> home
>> public_html (webroot)
>> audio

> Your choice, not mine -discurraged by others too-
> Have the rewrite your way
> RewriteRule ^[^/]+/(.*\.mp3)$
> audio.php?op=serveaudio&file=%{DOCUMENT_ROOT}/audio/$1
>
> and don't forget the 'deny from all' ao in /audio/.htaccess
>
>
> HansH
>


That didn't work either. Seems like the only way I can get it to work is to
not use a bogus directory name. So if I have this

RewriteRule ^([^/\.]+).mp3$ audio.php?op=serveaudio&file=$1.mp3 [L]

and type in a url like www.mysite.com/file.mp3 it gets processed correctly
by the audio script which tells me the rewrite must be correct. But file
names like this are screwing it up:

john's file.mp3

john file.mp3 works but it is that apostrophe s that is screwing it up...
Man I can't believe how hard it is to come up with proper functioning
rewrite rules!

thanks,

brian


  #8 (permalink)  
Old 12-02-2006
Brian Huether
 
Posts: n/a
Default Re: ReWrite Rule Question


"Brian Huether" <bhuetherNO@comcastSPAM.net> wrote in message
news:LICdnZdu6pPgWOzYnZ2dnUVZ_hydnZ2d@comcast.com. ..
>
> "HansH" <hansh@invalid.invalid> wrote in message
> news:4571c22c$0$324$e4fe514c@news.xs4all.nl...
>> "Brian Huether" <bhuetherNO@comcastSPAM.net> schreef in bericht
>> news:9J-dnVqtzaojL-zYnZ2dnUVZ_h6dnZ2d@comcast.com...
>>>> Still I do think, though did not test,
>>>> RewriteRule ^[^/]+/(.*\.mp3)$
>>>> audio.php?op=serveaudio&file=%{DOCUMENT_ROOT}/../audio/$1
>>>> will handle a request like
>>>> /whatever/classic/mozart/5thsymphony.mp3
>>>> to stream
>>>> /audio/classic/mozart/5thsymphony.mp3
>>>
>>> I am having strange behavior. These urls should produce equivalent
>>> results:
>>> http://www.mysite.com/audio.php?op=s...&file=file.mp3
>>> http://www.mysite.com/audiostuff/file.mp3
>>>
>>> The php code that processes this is
>>> $op = $_REQUEST["op"];
>>> $file = $_REQUEST["file"];
>>> serveaudio($file);
>>> function serveaudio($file) {
>>> $link = "./audio/".$file;

>> The rewriterule given already provides the full local path[, I think]
>>
>>> //echo $link;
>>> //die();
>>>
>>> header("Location: " .$link);

>> That's NOT streaming, that is redirecting ...
>> ... take this [and more] advise ginven in the other thread:
>> < header("Content-Type: audio/x-mpeg");
>> < echo @file_get_contents($file);
>>
>>>
>>> }
>>>
>>> When I echo the link, they are identical. The first url will cause the
>>> audio to stream and the second gets me a 403 forbidden error and also
>>> the url line in the browser gets replaced with

>> ... replaced url, indeed your are redirecting ...
>>> http://www.mysite.com/audiostuff/aud...audio/file.mp3

>> ... into endless circles
>>>
>>> current directory structure is
>>>
>>> home
>>> public_html (webroot)
>>> audio

>> Your choice, not mine -discurraged by others too-
>> Have the rewrite your way
>> RewriteRule ^[^/]+/(.*\.mp3)$
>> audio.php?op=serveaudio&file=%{DOCUMENT_ROOT}/audio/$1
>>
>> and don't forget the 'deny from all' ao in /audio/.htaccess
>>
>>
>> HansH
>>

>
> That didn't work either. Seems like the only way I can get it to work is
> to not use a bogus directory name. So if I have this
>
> RewriteRule ^([^/\.]+).mp3$ audio.php?op=serveaudio&file=$1.mp3 [L]
>
> and type in a url like www.mysite.com/file.mp3 it gets processed correctly
> by the audio script which tells me the rewrite must be correct. But file
> names like this are screwing it up:
>
> john's file.mp3
>
> john file.mp3 works but it is that apostrophe s that is screwing it up...
> Man I can't believe how hard it is to come up with proper functioning
> rewrite rules!
>
> thanks,
>
> brian
>
>


Meant to say that the above rewrite rule rewrites "john's file.mp3" as
"john/'s%20file.mp3" So the space is no problem but that 's is wreaking
havoc...


  #9 (permalink)  
Old 12-02-2006
HansH
 
Posts: n/a
Default Re: ReWrite Rule Question

"Brian Huether" <bhuetherNO@comcastSPAM.net> schreef in bericht
news:XaSdnS0JLPmgW-zYnZ2dnUVZ_t-dnZ2d@comcast.com...
>> RewriteRule ^([^/\.]+).mp3$ audio.php?op=serveaudio&file=$1.mp3 [L]
>>
>> and type in a url like www.mysite.com/file.mp3 it gets processed
>> correctly by the audio script which tells me the rewrite must be correct.
>> But file names like this are screwing it up:
>>
>> john's file.mp3
>>

> Meant to say that the above rewrite rule rewrites "john's file.mp3" as
> "john/'s%20file.mp3" So the space is no problem but that 's is wreaking
> havoc...

That magic is not performed by rewrite rules ...
.... it's PHP magic_quotes_runtime boolean
If magic_quotes_runtime is enabled, most functions that return
data from any sort of external source including databases and
text files will have quotes escaped with a backslash.

Try your luck this way:
<?php
$op = $_REQUEST["op"];
$file = $_REQUEST["file"];
if (get_magic_quotes_gpc() == 1) {
$op = stripslashes( $op );
$file = stripslashes( $file );
}
serveaudio($file);

function serveaudio($file) {
header("Content-Type: audio/x-mpeg");
echo @file_get_contents($file);
}
?>

HansH


  #10 (permalink)  
Old 12-02-2006
Brian Huether
 
Posts: n/a
Default Re: ReWrite Rule Question


"HansH" <hansh@invalid.invalid> wrote in message
news:4571e49c$0$337$e4fe514c@news.xs4all.nl...
> "Brian Huether" <bhuetherNO@comcastSPAM.net> schreef in bericht
> news:XaSdnS0JLPmgW-zYnZ2dnUVZ_t-dnZ2d@comcast.com...
>>> RewriteRule ^([^/\.]+).mp3$ audio.php?op=serveaudio&file=$1.mp3 [L]
>>>
>>> and type in a url like www.mysite.com/file.mp3 it gets processed
>>> correctly by the audio script which tells me the rewrite must be
>>> correct. But file names like this are screwing it up:
>>>
>>> john's file.mp3
>>>

>> Meant to say that the above rewrite rule rewrites "john's file.mp3" as
>> "john/'s%20file.mp3" So the space is no problem but that 's is wreaking
>> havoc...

> That magic is not performed by rewrite rules ...
> ... it's PHP magic_quotes_runtime boolean
> If magic_quotes_runtime is enabled, most functions that return
> data from any sort of external source including databases and
> text files will have quotes escaped with a backslash.
>
> Try your luck this way:
> <?php
> $op = $_REQUEST["op"];
> $file = $_REQUEST["file"];
> if (get_magic_quotes_gpc() == 1) {
> $op = stripslashes( $op );
> $file = stripslashes( $file );
> }
> serveaudio($file);
>
> function serveaudio($file) {
> header("Content-Type: audio/x-mpeg");
> echo @file_get_contents($file);
> }
> ?>
>
> HansH
>


I can't get this method to work

echo @file_get_contents($file);

It laucnhes Media Player after about 30 seconds but then Media Player just
says Connecting for about a minute and then pops up a little message that
says reached end of file. The only thing that has worked for me is

header("Location: " .$link);

That is a shame because I really want to be able to do this right...

later,

brian


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:18 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0