Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to rewrite all .mp3 files to a php file. And I dont want to pass on the path

so http://localhost/somepath/feb.mp3 http://localhost/feb.mp3

shouldn't do any difference.

I came up with:

RewriteRule ^(.*)\.mp3$ /files/read/?file=$1.mp3 [QSA]

What am I missing? maybe some regexp before the (.*) but why doesn't it pick up the mp3 pattern and redirect to /files/read/?file=feb.mp3 ?

This doesn't even seem to catch the mp3 files:

applying pattern '^(.*)\.mp3$' to uri 'feb.mp3'

It doesn't stop there, it goes through the other condition and falls under:

applying pattern '^.*$' to uri 'feb.mp3'
pass through /htdocs/project/project-web/feb.mp3

Many thanks if this can be solved.

this is my full .htaccess

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)\.mp3$ files/read/?file=$1.mp3 [QSA]
RewriteRule ^.*$ index.php [NC,L]

This seem to work, however it redirects it.

 RewriteRule ^(.+).mp3$ http://education.localhost/files/read/?file=$1.mp3 [NC,L]

It could be something that when this rewrite rule does apply, then this does not:

RewriteRule ^.*$ index.php [NC,L]

So files/read/?file=$1.mp3 this is dependent on that role to index.php, any way to get this to work?

share|improve this question

1 Answer 1

Make the rewriting process stop when an MP3 is found instead of sending the request to index.php, use the [L] flag.

And to make it not care what the directory path is preceding the MP3 filename, you'll want to exclude anything before the last slash character.

So, try this:

RewriteRule ([^/]*)\.mp3$ files/read/?file=$1.mp3 [QSA,L]

Or, did you mean to actually redirect the client, and still let it hit index.php on the subsequent request? I'm guessing so, since it's a query parameter... try this:

RewriteRule ([^/]*)\.mp3$ files/read/?file=$1.mp3 [QSA,L,R=301]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.