Christopher Penn
Christopher Penn

Reputation: 539

Extracting and redirecting MP3 file with rewriterule

Attempting to extract an MP3 file from a URL and repoint it elsewhere. Example:

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

Should become:

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

I've written this Rewriterule (and rewrite engine is on) and it works in regex101, but so far does nothing in apache's htaccess:

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

What am I doing wrong?

For context, the full section of my htaccess rewrite is:

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]

Upvotes: 1

Views: 151

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

You are using a wrong regex pattern to test the mp3 Uri. You should be using ^/?podcast-download/1443/(.+\.mp3)$

Try :

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

Upvotes: 1

Related Questions