Nginx – How to match nginx location block for non-whitespace character

nginxpcreregex

I'm trying to configure a workaround for google's WontFix search behavior in nginx by having a simple subfolder for my searches.

So far this is what I have.

 location ~* ^/search/(.*\..*)$ {
    return 307 http://$1;
  }
 location ~* ^/search/(.*)$ {
    return 307 https://www.google.com/search?q=$1;
  }

However this matches spaces, how can I update the first location block to only match non-whitespace characters.

Best Answer

Replaced * with \S+ was all I needed. (found what I needed in another exchange)

 location ~* ^/search/(.\S+\..\S+)$ {
    return 307 http://$1;
  }
 location ~* ^/search/(.*)$ {
    return 307 https://www.google.com/search?q=$1;
  }