# Temporary Redirect 307

**URL:** <https://www.ruby-forum.com/t/temporary-redirect-307/198026>\
**Category:** NGINX\
**Created:** [October 25, 2010, 9:08am UTC](https://www.ruby-forum.com/t/temporary-redirect-307/198026 "2010-10-25T09:08:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [October 25, 2010, 9:08am UTC](https://www.ruby-forum.com/t/temporary-redirect-307/198026/1 "2010-10-25T09:08:19Z")

</div>

Hi, I cannot find anywhere an answer to the following rather simple  
question .

How can i make a temporary (307) redirect using nginx.

For example i want to have this:

set $optika PUBLICIP;  
if ($host != $optika) {  
rewrite ^/(.\*)$ http://$optika/$1 redirect;  
break;  
}

So for example i have:  
[http://example.com/largefile.mpg](http://example.com/largefile.mpg)

i want to redirect it to:  
[http://XX.XX.XX.XX/largefile.mpg](http://XX.XX.XX.XX/largefile.mpg) (which is a faster link but with a  
dynamic ip)

the moment the IP is changed the PUBLICIP is updated and the nginx  
config is reloaded…  
The browsers which already asked for the file will cache it and will  
directly try to find via the PUBLICIP which is no longer valid. I need  
them to re-ask the [example.com](http://example.com) again so it gives them the correct  
location. I understand that this is done via 307 rather than the default  
302 which nginx uses… Do i need to recompile? What if i need both 302  
and 307 etc etc…

Thank you very much in advance.

---

<div class="post-metadata">

**Author:** ![Igor\_Janevski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ee59a6/32.png) [@Igor\_Janevski](https://www.ruby-forum.com/u/Igor_Janevski)\
**Post date:** [October 25, 2010, 9:25am UTC](https://www.ruby-forum.com/t/temporary-redirect-307/198026/2 "2010-10-25T09:25:20Z")

</div>

On 10/25/10 11:05, Igor Janevski wrote:

> }  
> rewrite … redirect  
> return http 302 and it is temporary redirect.

From RFC:

10.3.3 302 Found

The requested resource resides temporarily under a different URI. Since  
the  
redirection might be altered on occasion, the client SHOULD continue to  
use the  
Request-URI for future requests. This response is only cacheable if  
indicated by  
a Cache-Control or Expires header field.

Why you need http 307?

–  
Anton Y.

---

<div class="post-metadata">

**Author:** ![Igor\_Janevski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ee59a6/32.png) [@Igor\_Janevski](https://www.ruby-forum.com/u/Igor_Janevski)\
**Post date:** [October 26, 2010, 4:56am UTC](https://www.ruby-forum.com/t/temporary-redirect-307/198026/3 "2010-10-26T04:56:31Z")

</div>

As far as i can tell google chrome on linux does that and IE for sure.  
To be more precise whenever i have a JS, PNG or something static and the  
IP changes the browser still uses the last IP and fails loading.  
Probably it might be the cache settings but i don’t want to change  
anything else in the configuration . I read somewhere that 307 redirects  
are not cached by the browser, i.e. it will request it again from the  
original adress (the static one, [http://example.com/big.mpg](http://example.com/big.mpg)) , that one  
will redirect to the dynamic which will return the data or or just  
not-modified …

IMHO, that clearly differs from 302 redirect .
