'Nginx force redirect or rewrite mp3 url path
I have this mp3 url:
http://example.com/downloads/low_quality/songs/song_name.mp3
and i want force rewrite to this url without allow downloading first url:
http://example.com/downloads/high_quality/songs/song_name.mp3
Indeed i need replace low_quality with high_quality path. I trying use alias and rewrite, but not working. it start downloading first url low_quality.
location /downloads/low_quality/ {
alias /downloads/high_quality/;
}
or
location ~* ^/downloads/low_quality/(.*)$ {
rewrite ^/downloads/low_quality/(.*)$ http://example.com/downloads/high_quality/$1 permanent;
break;
}
// but low quality download started!
low_quality file always is exists but i don't want downloading when requested. i want redirect(rewrite) to second url high_quality.
Solution 1:[1]
according to https://www.nginx.com/blog/creating-nginx-rewrite-rules/
this is true rewrite:
rewrite ^/downloads/low_quality/songs/(\w+)\.?.*$ /downloads/high_quality/songs/$1.mp3 last;
high quality requested and downloaded.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Farzad |
