# Help with a rewrite rule

**URL:** <https://www.ruby-forum.com/t/help-with-a-rewrite-rule/194944>\
**Category:** NGINX\
**Created:** [September 14, 2010, 3:50am UTC](https://www.ruby-forum.com/t/help-with-a-rewrite-rule/194944 "2010-09-14T03:50:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mindfrost82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc79bd/32.png) [@mindfrost82](https://www.ruby-forum.com/u/mindfrost82)\
**Post date:** [September 14, 2010, 3:50am UTC](https://www.ruby-forum.com/t/help-with-a-rewrite-rule/194944/1 "2010-09-14T03:50:37Z")

</div>

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](http://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](http://www.website.com/download.php?device=device1&file=file1.zip)

Any ideas?

Posted at Nginx Forum:

> **[Help with a rewrite rule](https://forum.nginx.org/read.php?2,130176,130176#msg-130176)**
>
> 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...
