This is a discussion on mod_rewrite & headers within the Apache Web Server forums, part of the Web Server and Related Forums category; If I use mod_rewrite to rewrite a requested url will it preserve the headers of the requesting file? e.g. ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
If I use mod_rewrite to rewrite a requested url will it preserve the
headers of the requesting file? e.g. request www.mysite.com/audio/file1.mp3 - setting range offset within header (range: bytes=1025700-) rewrites to www.mysite.com/audio/process.php?p=file1.mp3 Ideally I want the process.php file to pickup the requesting file and serve it up as partial content, which is why I need to get the original header. Is this possible using mod_rewrite? Many thanks Dave |
|
|||
|
On Thu, 15 Feb 2007 14:39:31 +0100, Dave <spambox.dccobb@gmail.com> wrote:
> If I use mod_rewrite to rewrite a requested url will it preserve the > headers of the requesting file? > > e.g. > > request www.mysite.com/audio/file1.mp3 - setting range offset within > header (range: bytes=1025700-) > rewrites to www.mysite.com/audio/process.php?p=file1.mp3 Headers & post values will be preserved on internal redirects, get variables can be easily overwritten by accident if one's not carefull. -- Rik Wasmus |
|
|||
|
On Thu, 15 Feb 2007 15:12:12 +0100, Dave <spambox.dccobb@gmail.com> wrote:
> >> Headers & post values will be preserved on internal redirects, get >> variables can be easily overwritten by accident if one's not carefull.. > > Sorry, I'm not sure what you mean by your last statement. > The part about the GET variables? Most rewriting is done to get variables, for instance: http://example.com/foo/bar Is rewritten internally to: http://example.com/index.php?foz=foo&baz=bar That's a piece of cake, and usally works. Now what if we're trying this URL: http://example.com/foo/bar?foz=var It's highly dependant on the actual rewrite and/or the receiving script wether this script thinks the GET variable foz is 'var', 'foo', or maybe both. While POST & HEADER values can be altered, this most be done very explicitly, so it's very hard to do it by accidant. Not so for the GET. -- Rik Wasmus |
|
|||
|
> The part about the GET variables? > Most rewriting is done to get variables, for instance: > http://example.com/foo/bar > Is rewritten internally to: > http://example.com/index.php?foz=foo&baz=bar > > That's a piece of cake, and usally works. Now what if we're trying this > URL: > http://example.com/foo/bar?foz=var > > It's highly dependant on the actual rewrite and/or the receiving script > wether this script thinks the GET variable foz is 'var', 'foo', or maybe > both. > > While POST & HEADER values can be altered, this most be done very > explicitly, so it's very hard to do it by accidant. Not so for the GET. > -- > Rik Wasmus Rik, With you. I won't need to request files with additional values passed on the querystring. So the first example will apply. As long as I can read the requesting header information, then I should be fine. Many thanks Dave |
|
|||
|
On 15 Feb, 14:57, "Dave" <spambox.dcc...@gmail.com> wrote:
> > The part about the GET variables? > > Most rewriting is done to get variables, for instance: > > http://example.com/foo/bar > > Is rewritten internally to: > > http://example.com/index.php?foz=foo&baz=bar > > > That's a piece of cake, and usally works. Now what if we're trying this > > URL: > > http://example.com/foo/bar?foz=var > > > It's highly dependant on the actual rewrite and/or the receiving script > > wether this script thinks the GET variable foz is 'var', 'foo', or maybe > > both. > > > While POST & HEADER values can be altered, this most be done very > > explicitly, so it's very hard to do it by accidant. Not so for the GET. > > -- > > Rik Wasmus > > Rik, > > With you. I won't need to request files with additional values passed > on the querystring. So the first example will apply. As long as I can > read the requesting header information, then I should be fine. > > Many thanks > > Dave $_SERVER["HTTP_RANGE"] is what you need, and then you need to send back a couple of headers to the application which plays the mpeg: for instance here is the RR cycle for a raw mp3: GET /readings/listen/esv/February15.mp3 HTTP/1.1 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv: 1.8.1.1) Gecko/20061204 Firefox/2.0.0.1 Accept: text/xml,application/xml,application/xhtml+xml,text/ html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Keep-Alive: 300 Range: bytes=417792- If-Range: "228f8-3a43cd-708051a3" HTTP/1.1 206 Partial Content Date: Thu, 15 Feb 2007 22:33:25 GMT Server: Microsoft-IIS/7.0 Last-Modified: Wed, 14 Feb 2007 00:01:07 GMT ETag: "228f8-3a43cd-708051a3" Accept-Ranges: bytes Content-Length: 3400653 Vary: User-Agent Content-Range: bytes 417792-3818444/3818445 Content-Type: audio/mpeg the user-agent knew the Etag for the mp3, apache responds with this e- tag as well as the Content-Range, and Accept-Ranges headers make sure you generate the right headers with your php script and you should be fine, and then of course read from the correct offset!! |
|
|||
|
On 15 Feb, 22:45, "shimmyshack" <matt.fa...@gmail.com> wrote:
> On 15 Feb, 14:57, "Dave" <spambox.dcc...@gmail.com> wrote: > > > > > > The part about the GET variables? > > > Most rewriting is done to get variables, for instance: > > > http://example.com/foo/bar > > > Is rewritten internally to: > > > http://example.com/index.php?foz=foo&baz=bar > > > > That's a piece of cake, and usally works. Now what if we're trying this > > > URL: > > > http://example.com/foo/bar?foz=var > > > > It's highly dependant on the actual rewrite and/or the receiving script > > > wether this script thinks the GET variable foz is 'var', 'foo', or maybe > > > both. > > > > While POST & HEADER values can be altered, this most be done very > > > explicitly, so it's very hard to do it by accidant. Not so for the GET. > > > -- > > > Rik Wasmus > > > Rik, > > > With you. I won't need to request files with additional values passed > > on the querystring. So the first example will apply. As long as I can > > read the requesting header information, then I should be fine. > > > Many thanks > > > Dave > > $_SERVER["HTTP_RANGE"] is what you need, and then you need to send > back a couple of headers to the application which plays the mpeg: > for instance here is the RR cycle for a raw mp3: > GET /readings/listen/esv/February15.mp3 HTTP/1.1 > User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv: > 1.8.1.1) Gecko/20061204 Firefox/2.0.0.1 > Accept: text/xml,application/xml,application/xhtml+xml,text/ > html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 > Keep-Alive: 300 > Range: bytes=417792- > If-Range: "228f8-3a43cd-708051a3" > > HTTP/1.1 206 Partial Content > Date: Thu, 15 Feb 2007 22:33:25 GMT > Server: Microsoft-IIS/7.0 > Last-Modified: Wed, 14 Feb 2007 00:01:07 GMT > ETag: "228f8-3a43cd-708051a3" > Accept-Ranges: bytes > Content-Length: 3400653 > Vary: User-Agent > Content-Range: bytes 417792-3818444/3818445 > Content-Type: audio/mpeg > > the user-agent knew the Etag for the mp3, apache responds with this e- > tag as well as the Content-Range, and Accept-Ranges headers > > make sure you generate the right headers with your php script and you > should be fine, and then of course read from the correct offset!! I suppose I should add that theres a great resource at http:// www.ampache.com for instance in the play folder theres a file called index.php which has these lines: if ($start) { debug_event('seek','Content-Range header recieved, skipping ahead ' . $start . ' bytes out of ' . $song->size,'5'); $browser->downloadHeaders($song_name, $song->mime, false, $song- >size); fseek( $fp, $start ); $range = $start ."-". ($song->size-1) . "/" . $song->size; header("HTTP/1.1 206 Partial Content"); header("Content-Range: bytes=$range"); header("Content-Length: ".($song->size-$start)); } I havent determined whether it can handle streaming at just above the average bit rate, which can be useful, but it seems an active project. Although some of the code is a work in progress. |
|
|||
|
Yes, that's pretty much how I've done this in .NET
I couldn't find much at http://www.ampache.com, sorry. Just one other question... I'm trying to resolve this rule: RewriteRule ^test.html?s=([0-9]+)&b=([0-9]+) /folder$1/$2/test.html where you would supply test.html?s=2&b=14016, which would rewrite the url to: /folder2/14016/test.html However, I can't get it to work using the above rule. Can anyone help please? Thanks Dave |
|
|||
|
On 16 Feb, 14:02, "Dave" <spambox.dcc...@gmail.com> wrote:
> Yes, that's pretty much how I've done this in .NET > I couldn't find much athttp://www.ampache.com, sorry. > > Just one other question... > > I'm trying to resolve this rule: > > RewriteRule ^test.html?s=([0-9]+)&b=([0-9]+) /folder$1/$2/test.html > > where you would supply test.html?s=2&b=14016, which would rewrite the > url to: /folder2/14016/test.html > > However, I can't get it to work using the above rule. Can anyone help > please? > > Thanks > > Dave sorry my mistake: http://www.ampache.org it seems strange to me that you are rewriting things this way when you could just later the links. However you can use ReWriteCond %{QUERY_STRING} s=([0-9]+)&b=([0-9]+) RewriteRule . /folder%1/%2/test.html [L,NS] where the syntax %1 rather than $1 is because it matches against the last conditions. |