# Insert subdomain into query

**URL:** <https://www.ruby-forum.com/t/insert-subdomain-into-query/238260>\
**Category:** NGINX\
**Created:** [December 29, 2013, 9:26pm UTC](https://www.ruby-forum.com/t/insert-subdomain-into-query/238260 "2013-12-29T21:26:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [December 29, 2013, 9:26pm UTC](https://www.ruby-forum.com/t/insert-subdomain-into-query/238260/1 "2013-12-29T21:26:34Z")

</div>

I have setup a wildcard subdomain server(many subdomains)  
server {  
listen 80;  
server\_name ~(?.\*).localhost;  
…  
…  
}

I want to make the subdomain apart of the query in the backend

when we visit [http://clothes.localhost/](http://clothes.localhost/)  
backend query  
[http://localhost/script.php?sd=clothes](http://localhost/script.php?sd=clothes)

or we visit [http://jackets.localhost/large/blue/](http://jackets.localhost/large/blue/)  
backend query  
[http://localhost/script.php?sd=jackets&size=large&colour=blue](http://localhost/script.php?sd=jackets&size=large&colour=blue)

I have tried for 5 hours now, Modifying rewrite and return as many ways  
possible, Multiple errors such as

rewrite ^ http://$subdomain.localhost/script.php?x=$subdomain permanent;

[http://clothes.localhost/script.php/script.php/script.php/script.php/script.php/script.php/script.php/script.php/?sd=clothes?sd=clothes&sd=clothes?sd=clothes&sd=clothes?sd=clothes&sd=clothes?sd=clothes&](http://clothes.localhost/script.php/script.php/script.php/script.php/script.php/script.php/script.php/script.php/?sd=clothes?sd=clothes&sd=clothes?sd=clothes&sd=clothes?sd=clothes&sd=clothes?sd=clothes&)  
or  
[http://localhost/localhost/localhost/localhost/localhost](http://localhost/localhost/localhost/localhost/localhost)

etc etc(I have tried many more tweaks but didnt record all as I went  
along)

Thanks in advance for any intention to help or answers given.

Posted at Nginx Forum:

> **[insert subdomain into query](https://forum.nginx.org/read.php?2,245906,245906#msg-245906)**
>
> I have setup a wildcard subdomain server(many subdomains) server { listen 80; server\_name ~(?\<subdomain\>.\*).localhost; ... ... } I want to make the subdomain apart of the query in the backend when we visit ht
