# Hello maybe someone can help with simple rewrites

**URL:** <https://www.ruby-forum.com/t/hello-maybe-someone-can-help-with-simple-rewrites/208366>\
**Category:** NGINX\
**Created:** [June 16, 2011, 1:01pm UTC](https://www.ruby-forum.com/t/hello-maybe-someone-can-help-with-simple-rewrites/208366 "2011-06-16T13:01:50Z")\
**Posts on this page:** 1\
**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:** [June 16, 2011, 1:01pm UTC](https://www.ruby-forum.com/t/hello-maybe-someone-can-help-with-simple-rewrites/208366/1 "2011-06-16T13:01:50Z")

</div>

Hello,

I have difficulty converting these rewrite rules of apache into nginx.  
Could someone please provide a helping hand.

RewriteRule ^(.\*)$ %{SERVER\_NAME}$1  
[C]

RewriteCond %{SERVER\_NAME}  
^(._).example.com$  
RewriteRule ^([a-z0-9-]+).example.com/(._)$  
/home/www/$1/$2 [L]

so if i go to [test.example.com](http://test.example.com) it should redirect me to  
/home/www/test/index.php|html  
etc.

but in nginx somehow I get 2011/06/16 05:31:15 [error] 28649#0: \*1  
open() "/home/www///

it somehow does not recognize variables.

```
  server_name ~^(.*)$;

   if ( $host ~ ^(.*)\.example\.com$ ) {
  rewrite ^([a-z0-9-]+)\.example\.com/(.*)$ 

```

/home/www/$1/$2 last;  
}

root /home/www/$1/$2

Sincerely,  
Arvydas
