The "^/$" came from : #to detect if the device with www entered in domain is mobile if ($http_user_agent ~* '(iPhone|iPod|iPad|Android|BlackBerry|webOS|Windows Phone)') { rewrite ^/$ http://m.domain.com$request_uri; } Posted at Nginx Forum: http://forum.nginx.org/read.php?2,260033,260097#msg-260097