用重写器提取和重定向MP3文件

时间:2019-01-31 15:30:36

标签: apache mod-rewrite url-rewriting

尝试从URL提取MP3文件并将其重新指向其他位置。示例:

https://www.trustinsights.ai/podcast-download/1443/in-ear-insights-public-speaking-tips-and-tricks.mp3?ref=download

应成为:

http://traffic.libsyn.com/inearinsights/in-ear-insights-public-speaking-tips-and-tricks.mp3

我已经编写了这个Rewriterule(并且重写引擎处于打开状态),并且可以在regex101中使用,但是到目前为止,在apache的htaccess中什么都没做:

RewriteRule [^/\\&\?]+\.\mp3(?=([\?&].*$|$)) http://traffic.libsyn.com/inearinsights/$1 [R]

我在做什么错了?

对于上下文,我的htaccess重写的整个部分是:

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule [^/\\&\?]+\.\mp3(?=([\?&].*$|$)) http://traffic.libsyn.com/inearinsights/$1 [R]

1 个答案:

答案 0 :(得分:1)

您使用了错误的正则表达式模式来测试mp3 Uri。您应该使用^/?podcast-download/1443/(.+\.mp3)$

尝试:

RewriteEngine On
RewriteRule ^/?podcast-download/1443/(.+\.mp3)$ http://traffic.libsyn.com/inearinsights/$1?  [L,R]