# Location header rewrite

**URL:** <https://www.ruby-forum.com/t/location-header-rewrite/214521>\
**Category:** NGINX\
**Created:** [December 4, 2011, 4:23pm UTC](https://www.ruby-forum.com/t/location-header-rewrite/214521 "2011-12-04T16:23:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [December 4, 2011, 4:23pm UTC](https://www.ruby-forum.com/t/location-header-rewrite/214521/1 "2011-12-04T16:23:56Z")

</div>

How do I go about rewriting the Location header in a response?  
I have setup nginx as a reverse proxy to a web mail server. Everything  
run good if data is self contain on that server. When an email have  
links to different servers in its environment, it sends the Locations  
header with the uri to it. How do I go about search and replace these  
value.

I have tried the proxy\_redirect but it doesn’t work.  
I have looked at both the header and headers\_more module but it doesn’t  
provide a search and replace function.

Posted at Nginx Forum:

> **[Location header rewrite](https://forum.nginx.org/read.php?2,219582,219582#msg-219582)**
>
> How do I go about rewriting the Location header in a response? I have setup nginx as a reverse proxy to a web mail server. Everything run good if data is self contain on that server. When an email have links to different servers in its environment,...

---

<div class="post-metadata">

**Author:** ![nguyen.tho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9bcb4/32.png) [@nguyen.tho](https://www.ruby-forum.com/u/nguyen.tho)\
**Post date:** [December 4, 2011, 7:45pm UTC](https://www.ruby-forum.com/t/location-header-rewrite/214521/2 "2011-12-04T19:45:43Z")

</div>

> 

The proxy\_redirect should help.  
May you show your nginx config and expected/ HTTP Location headers in  
response?

---

<div class="post-metadata">

**Author:** ![nguyen.tho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9bcb4/32.png) [@nguyen.tho](https://www.ruby-forum.com/u/nguyen.tho)\
**Post date:** [December 4, 2011, 7:46pm UTC](https://www.ruby-forum.com/t/location-header-rewrite/214521/3 "2011-12-04T19:46:58Z")

</div>

> > 
> 
> The proxy\_redirect should help.  
> May you show your nginx config and expected/ HTTP Location headers in response?

\*expected/observed HTTP Location headers in response

---

<div class="post-metadata">

**Author:** ![nguyen.tho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9bcb4/32.png) [@nguyen.tho](https://www.ruby-forum.com/u/nguyen.tho)\
**Post date:** [December 5, 2011, 8:01am UTC](https://www.ruby-forum.com/t/location-header-rewrite/214521/4 "2011-12-05T08:01:20Z")

</div>

After a bunch of hours not looking at it, I found my problem. With too  
many commented out line and apparently I have a proxy\_redirect off; line  
so it never rewrite it even though I have the proxy\_redirect lines.

Thanks.

Posted at Nginx Forum:

> **[Re: Location header rewrite](https://forum.nginx.org/read.php?2,219582,219604#msg-219604)**
>
> How do I go about rewriting the Location header in a response? I have setup nginx as a reverse proxy to a web mail server. Everything run good if data is self contain on that server. When an email have links to different servers in its environment,...
