exclude a category from a search on a specific page

The problem is that pre_get_posts is called after you leave the page, so you must also test to see if the search was done from there and for that you can use wp_get_referer()

So (in theory, sorry I haven’t the time to test this) you could have

if ( !is_admin() && $query->is_search() && $query->is_main_query() && wp_get_referer() == "http://www.example.com/archive" ) {

Hope that helps

PS: Always add a !is_admin() check to make double-sure you’re not effecting admin queries… belt & braces!