nginx rewrite subdomain to file as a variable

Posted by ethree on Server Fault See other posts from Server Fault or by ethree
Published on 2012-12-15T00:01:25Z Indexed on 2012/12/15 5:08 UTC
Read the original article Hit count: 508

Filed under:
|

How do you get the subdomain as a variable to add in a rewrite?

hello.example.com should go to example.com/user.php?u=hello but still display as just hello.example.com

I'm currently doing http://example.com/users/hello but would like to have Tumblr style domain names for users.

rewrite ^/users/(.*)$ /user.php?u=$1 last;

Also, if there are pages like /settings/ after the subdomain hello.example.com/settings/ I'll need to rewrite to a settings.php

© Server Fault or respective owner

Related posts about nginx

Related posts about rewrite