我想重写所有.mp3文件到一个php文件。 而我不想传递的path
所以http://localhost/somepath/feb.mp3 http://localhost/feb.mp3
应该没有什么区别。
我想出了:
RewriteRule ^(.*)\.mp3$ /files/read/?file=$1.mp3 [QSA]
我错过了什么? 也许一些正则expression式(。*)之前,但为什么不拿起MP3模式,并redirect到/files/read/?file=feb.mp3?
这似乎甚至没有赶上MP3文件:
applying pattern '^(.*)\.mp3$' to uri 'feb.mp3'
它并没有停在那里,它经历了另一个条件,
applying pattern '^.*$' to uri 'feb.mp3' pass through /htdocs/project/project-web/feb.mp3
非常感谢,如果这可以解决。
这是我的完整.htaccess
SetEnv APPLICATION_ENV开发
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]
这似乎工作,但它redirect它。
RewriteRule ^(.+).mp3$ http://education.localhost/files/read/?file=$1.mp3 [NC,L]
这可能是当这个重写规则适用时,那么这不是:
RewriteRule ^.*$ index.php [NC,L]
所以文件/读/?文件= $ 1.mp3这是依赖于该angular色index.php,任何方式来得到这个工作?
当findMP3时,重写过程停止,而不是发送请求到index.php ,使用[L]标志。
为了不关心MP3文件名前的目录path,你需要排除最后一个斜杠之前的任何内容。
所以,试试这个:
RewriteRule ([^/]*)\.mp3$ files/read/?file=$1.mp3 [QSA,L]
或者,你的意思是实际redirect客户端,并仍然让它在随后的请求上打index.php? 我猜是这样,因为它是一个查询参数…试试这个:
RewriteRule ([^/]*)\.mp3$ files/read/?file=$1.mp3 [QSA,L,R=301]