Nginx:通配符dns将URLredirect到子域名

我正在尝试redirect以下url

Http://example.com/category/something 

redirect到

 Http://something.example.com/category/something 

“什么”可以是任何东西。

我已经为通配符设置了nginx和Dns,并确认了这一点。

正统的方式在哪里:

 location /category/ { location ~ ^/category/(?<category>.+)$ { return 302 http://$category.example.com/category/$category } } 

没有“重写”。 在nginx / 1.0.0testing

未经testing..但应该工作

 location / { rewrite ^/category/(.*)$ http://$1.example.com/category/$1 permanent; }