Skip to content

Instantly share code, notes, and snippets.

@drakemccabe
Created August 23, 2016 02:50
Show Gist options
  • Save drakemccabe/7e4ce3281b9d4688c60f408e0260e256 to your computer and use it in GitHub Desktop.
Save drakemccabe/7e4ce3281b9d4688c60f408e0260e256 to your computer and use it in GitHub Desktop.
common varnish vcl functions
# call fucntion in vcl_res
# Throw error on spam bot comment attempt
# if first letter of comment ID is not numeric, throw 404.
sub clean_comment {
if (req.url ~ "comment\/reply\/\d*\/\D") {
error 404 "Page Not Found";
}
}
# normalize url
sub normalize_req_url {
if (req.url ~ "^/(?:\?.*)?$") {
set req.url = "/";
}
if (req.url ~ "(\?|&)(campname|camplink|utm_[a-z]+)") {
set req.url = regsuball(req.url, "(campname|camplink|utm_[a-z]+)=[%\._A-z0-9-]+&?", "");
}
set req.url = regsub(req.url, "(\?&|\?|&)$", "");
}
## block specific hostname
if ( req.http.host ~ "(hostname\.com)$" ) {
error 403 "Access denied";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment