Welcome! Log In Create A New Profile

Advanced

Wildcard Subdomains to file nginx rewrites

Posted by jacobtalbot 
Wildcard Subdomains to file nginx rewrites
October 23, 2010 10:16AM
We have just transferred over to Nginx, and so far we love the stability, and the speed it offers over Apache. However, with Apache we had the ability to have "username.domain,com" setup in our re-writes, which pointed to "file.php?id=username", however I cannot figure out a way to do this similar in nginx.

Could someone help us out.

Cheers,

Jacob
Re: Wildcard Subdomains to file nginx rewrites
November 12, 2010 02:57PM
Something like this might work:
[code]
if ($host ~* (.*)\.domain\.com) {
$user = $1;
rewrite ^(.*)$ http://domain.com/file.php?=$user permanent;
}
[/code]

Note that this will not work for www.user.domain.com, although you can add that easily enough. Likewise, without a qualifier, it'll also consider www.domain.com a user and forward accordingly.
Re: Wildcard Subdomains to file nginx rewrites
November 12, 2010 03:10PM
That's missing the word 'set' before then $user declaration line, btw (too late to edit the post).
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 87
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready