Skip to content

Instantly share code, notes, and snippets.

@mechiland
Created February 28, 2013 08:09
Show Gist options
  • Save mechiland/5055089 to your computer and use it in GitHub Desktop.
Save mechiland/5055089 to your computer and use it in GitHub Desktop.
nginx allow crawler to visit website
map $http_user_agent $is_bot {
default 0;
~*(crawl|Googlebot|Slurp|spider|bingbot|yodaobot|youdaobot)$ 1;
}
set $should_redirect 1;
if ($is_bot) {
set $should_redirect 0;
}
if ($ssl_protocol != "") {
set $should_redirect 0;
}
if ($should_redirect = 1) {
rewrite ^ https://$host$request_uri? permanent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment