# Strip Character from Server Variable

**URL:** <https://www.ruby-forum.com/t/strip-character-from-server-variable/217390>\
**Category:** NGINX\
**Created:** [February 29, 2012, 3:38pm UTC](https://www.ruby-forum.com/t/strip-character-from-server-variable/217390 "2012-02-29T15:38:37Z")\
**Posts on this page:** 3\
**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:** [February 29, 2012, 3:38pm UTC](https://www.ruby-forum.com/t/strip-character-from-server-variable/217390/1 "2012-02-29T15:38:37Z")

</div>

Hi all,

I am trying to do something that sounds very simple and yet has me  
perplexed. I need to strip the leading / from the $uri variable in my  
nginx.conf. I need to then pass that modified variable to ProxyPass.

I can’t for the life of me figure out how to this in the nginx.conf  
syntax.

Thanks in advance.

James

Posted at Nginx Forum:

> **[Strip Character from Server Variable](https://forum.nginx.org/read.php?2,223166,223166#msg-223166)**
>
> Hi all, I am trying to do something that sounds very simple and yet has me perplexed. I need to strip the leading / from the $uri variable in my nginx.conf. I need to then pass that modified variable to ProxyPass. I can't for the life of me figure...

---

<div class="post-metadata">

**Author:** ![jamessinton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jamessinton](https://www.ruby-forum.com/u/jamessinton)\
**Post date:** [February 29, 2012, 3:53pm UTC](https://www.ruby-forum.com/t/strip-character-from-server-variable/217390/2 "2012-02-29T15:53:35Z")

</div>

On Wednesday 29 February 2012 18:38:14 jamessinton wrote:

> 

map $uri $uri\_stripped {  
default $uri;  
~^/(?P~~.\*)$ $s;  
}~~

 

[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpMapModule)

or

```
if ($uri ~ "^/(.*)$") {
    set $uri_stripped $1;
}

```

[Module ngx\_http\_rewrite\_module](http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if)  
[Module ngx\_http\_rewrite\_module](http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#set)

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![jamessinton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jamessinton](https://www.ruby-forum.com/u/jamessinton)\
**Post date:** [February 29, 2012, 3:57pm UTC](https://www.ruby-forum.com/t/strip-character-from-server-variable/217390/3 "2012-02-29T15:57:56Z")

</div>

On Wednesday 29 February 2012 18:52:40 Valentin V. Bartenev wrote:

> > Thanks in advance.  
> > if ($uri ~ “^/(.\*)$”) {  
> > set $uri\_stripped $1;  
> > }
> 
> [Module ngx\_http\_rewrite\_module](http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if)  
> [Module ngx\_http\_rewrite\_module](http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#set)

or, maybe you just want this:

```
 location ~ ^/(.*)$ {
     ...
     fastcgi_param SOME $1; # just for example
 }

```

wbr, Valentin V. Bartenev
