1

We've got 130 urls (some query query strings) that we need to serve up our normal 404 page, however return a 410 header.

The list looks something like, just a complete mixture of stuff

https://www.example.com/blog/wp-loads.php?q=82
https://www.example.com/blog/wp-loads.php?q=94
https://www.example.com/mph
https://www.example.com/blog/example-football
https://www.example.com/blog/wp-loads.php?q=24
https://www.example.com/services/Email-marketing.htm
https://www.example.com/blog/2013/02/adaptive-vs-responsive-web-design
https://www.example.com/blog/2013/04/magic-with-css3
https://www.example.com/services/Digital-Creative-Services-Overview.htm
https://www.example.com/services/Email-Marketing.htm?__hstc=60812914.e835c34ab7bf88e972fdd7a7debc8575.1453680000065.1453680000066.1453680000067.1&__hssc=60812914.2.1453680000068&__hsfp=3972014050
https://www.example.com/blog/forums/forum/general-chat
https://www.example.com/blog/wp-loads.php?q=87
https://www.example.com/blog/2013/04/improved-targeting-with-google-adwords-enhanced-campaigns
https://www.example.com/blog/forums/topic/checking-out-the-forum
https://www.example.com/blog/forums/topic-tag/balloons-conduction-fun
https://www.example.com/blog/ramblings
https://www.example.com/blog/twelve-christmas-crackers
https://www.example.com/blog/a-new-awesome-pair-of-hands-in-the-client-services-team
https://www.example.com/services/motion-graphics-and-flash.htm
https://www.example.com/services/translation-services-and-website-copy.htm

We're trying to figure out whats the best way in the nginx conf to mass/bulk 410 these?

Thanks

owenmelbz
  • 163
  • 3
  • 12
  • Defining these in a map might be possible and more efficient, but I don't have details at this moment. http://nginx.org/en/docs/http/ngx_http_map_module.html#map – virullius Dec 05 '17 at 21:23

1 Answers1

-1

For plain URLs, as there's nothing particularly consistent create a conf file with entries like this:

location ~ /blog/example-football { return 410; }

However, a location block won't handle query strings. They are returned in the variable $args or named in the variable $arg_name so if you have specific query URIs that need to return 410, create a map outside of the server something like this:

map $arg_q $response {
    default 0;
    87 1;
    94 1;
    ...
}

Then in your location block, remembering that If is Evil

location ~ /blog/wp-loads.php {

    if ($response = 1) {
         return 410;
    }
}
Simon Greenwood
  • 1,363
  • 9
  • 12
  • So would literally need 1 line per url? no way to parse the rule for all? – owenmelbz Dec 05 '17 at 16:08
  • I can't think of anything unfortunately. In its favour it's quite easy to script if you have a list. If you had some consistent patterns you could have some regexes, and if you had a consistent pattern now and these were legacy URLs you could possibly do something with a pattern that wasn't your current URLs (if that makes sense). – Simon Greenwood Dec 05 '17 at 17:46
  • This does not work, one cannot match query arguments in `location` blocks, since nginx only uses normalised URIs as the comparison item for the `location` block. One needs to use a `map`. – Tero Kilkanen Dec 06 '17 at 15:41
  • @TeroKilkanen updated with an example. – Simon Greenwood Dec 07 '17 at 07:58