Help with a rewrite rule

I need some help with creating a rewrite rule for a virtual host on my
nginx server. I’m not very familiar with rewrite rules, so I’m hoping
someone can help…if its even possible.

Basically, I have a script that works like a file explorer that offers
downloads and I want to do a rewrite rule to pull a PHP page that serves
an ad and will start the download within 10-15 seconds.

After thinking about it, I’m not sure if a rewrite rule is actually what
I need or if its some sort of redirect script, so maybe someone can shed
some light on it.

Here’s an example:

When you click on the link in the file explorer script, it’ll let you
download a file at www.website.com/device1/file1.zip (the direct path to
where the file is on the server).

Instead of serving that file directly for download, we want it to pull
up a download.php script that shows an ad and starts the download after
xx amount of time. So the download script might look like
www.website.com/download.php?device=device1&file=file1.zip

Any ideas?

Posted at Nginx Forum: