# Rewrite all urls inside location block in nginx

**URL:** <https://www.ruby-forum.com/t/rewrite-all-urls-inside-location-block-in-nginx/225252>\
**Category:** NGINX\
**Created:** [December 24, 2012, 11:01am UTC](https://www.ruby-forum.com/t/rewrite-all-urls-inside-location-block-in-nginx/225252 "2012-12-24T11:01:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [December 24, 2012, 11:01am UTC](https://www.ruby-forum.com/t/rewrite-all-urls-inside-location-block-in-nginx/225252/1 "2012-12-24T11:01:52Z")

</div>

Hello,

I have a config like  
location = /foo.xml { if ($scheme = https) { rewrite .\*  
http://$http\_host/foo.xml  
permanent; }}

But as you can see, the file is already matched with the location block,  
it  
seems to me the regex rewrite is wasting the CPU cycle, are there any  
better way to do it?

---

<div class="post-metadata">

**Author:** ![howard\_chen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bbce88/32.png) [@howard\_chen](https://www.ruby-forum.com/u/howard_chen)\
**Post date:** [December 24, 2012, 11:04am UTC](https://www.ruby-forum.com/t/rewrite-all-urls-inside-location-block-in-nginx/225252/2 "2012-12-24T11:04:12Z")

</div>

On Mon, Dec 24, 2012 at 5:01 PM, howard chen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

return 301 http://$http\_host/foo.xml;

---

<div class="post-metadata">

**Author:** ![howard\_chen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bbce88/32.png) [@howard\_chen](https://www.ruby-forum.com/u/howard_chen)\
**Post date:** [December 25, 2012, 11:56am UTC](https://www.ruby-forum.com/t/rewrite-all-urls-inside-location-block-in-nginx/225252/3 "2012-12-25T11:56:31Z")

</div>

Thanks.
