# Help with replacing chars "\_" to "." in a $variable

**URL:** <https://www.ruby-forum.com/t/help-with-replacing-chars-to-in-a-variable/215715>\
**Category:** NGINX\
**Created:** [January 13, 2012, 2:44pm UTC](https://www.ruby-forum.com/t/help-with-replacing-chars-to-in-a-variable/215715 "2012-01-13T14:44:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 13, 2012, 2:44pm UTC](https://www.ruby-forum.com/t/help-with-replacing-chars-to-in-a-variable/215715/1 "2012-01-13T14:44:42Z")

</div>

I would appreciate your help

I have to do the following request

http://subdomain\_domain\_extension\_tdl.domain.com/

Where .domain.com must be deleted and subdomain\_domain\_extension\_tdl  
must be converted to subdomain.domain.extension.tdl

I did this:

```
    set $subdomain "";

    if ($host ~* "^(.+)\.domain\.com$") {
        set $subdomain $1;
        break;
    }

      resolver 8.8.8.8;
      proxy_pass http://$subdomain;
      proxy_set_header X-Real-IP $remote_addr;

```

Then i get $subdomain as: subdomain\_domain\_extension\_tdl but i need to  
transform it into subdomain.domain.extension.tdl

Could you please help me determining how could i do this? i would like  
to serve as proxy in this way:

If you want to get inside any blocked website like [www.facebook.com](http://www.facebook.com) be  
able to do it throug www\_facebook\_com.domain.com

Also i know that perhaps sometimes subdomain\_domain\_extension\_tdl could  
be domain\_extension\_tdl,

Thanks in advance!  
Andrés

Posted at Nginx Forum:

> **[help with replacing chars "\_" to "." in a $variable](https://forum.nginx.org/read.php?2,221176,221176#msg-221176)**
>
> I would appreciate your help I have to do the following request http://subdomain\_domain\_extension\_tdl.domain.com/ Where .domain.com must be deleted and subdomain\_domain\_extension\_tdl must be converted to subdomain.domain.extension.tdl
