Nginx 强制重定向或重写 mp3 url 路径

Nginx force redirect or rewrite mp3 url path

我有这个 mp3 url:

http://example.com/downloads/low_quality/songs/song_name.mp3

我想强制重写这个 url 不允许先下载 url:

http://example.com/downloads/high_quality/songs/song_name.mp3

确实我需要用 high_quality 路径替换 low_quality。我尝试使用 aliasrewrite,但没有用。它首先开始下载 url low_quality.

location /downloads/low_quality/ {
    alias /downloads/high_quality/;
}

location ~* ^/downloads/low_quality/(.*)$ {
    rewrite ^/downloads/low_quality/(.*)$ http://example.com/downloads/high_quality/ permanent; 
    break;
}
// but low quality download started!

low_quality 文件始终存在,但我不想在请求时下载。我想重定向(重写)到第二个 url high_quality.

根据https://www.nginx.com/blog/creating-nginx-rewrite-rules/

这是真的重写:

rewrite ^/downloads/low_quality/songs/(\w+)\.?.*$ /downloads/high_quality/songs/.mp3 last;

请求并下载了高质量。