简体   繁体   English

返回 Wordpress 搜索页面的 404 错误,除非有人首先访问过该网站

[英]Return A 404 Error For Wordpress Search Page, Unless Someone Has Visited The Website First

Bit of a strange question here people.这里的人有点奇怪的问题。

Would like to be able to put together some code, so that if someone directly types in our website url, with the default Wordpress search query at the end www.ourdomain.com/?s=your search words, that this would return a 404 error, as we no that anyone typing in our website url, with a dodgy search url attached is a spam bot.希望能够将一些代码放在一起,这样如果有人直接在我们的网站中输入 url,在末尾使用默认的 Wordpress 搜索查询www.ourdomain.com/?s=your search words,这将返回 404错误,因为我们没有任何人在我们的网站 url 中输入,附带一个狡猾的搜索 url 是垃圾邮件机器人。

However, if someone were to land on our website first, and then type in a search query, the 404 page wouldn't be returned, as we know that they're likely to be a genuine customer and not a bot.但是,如果有人先登陆我们的网站,然后输入搜索查询,则不会返回 404 页面,因为我们知道他们很可能是真正的客户,而不是机器人。

Trying to stop a large search spam attack, that we're facing.试图阻止我们面临的大型搜索垃圾邮件攻击。

Have tried various plugins etc, with no luck so far, and suddenly thought of this as a possible answer?尝试过各种插件等,到目前为止没有运气,突然想到这是一个可能的答案?

Code to start with:开始的代码:

add_action( 'template_redirect', function () {
    
  if (is_search() ) {

Tried a few Wordpress plugins, but no luck with them at all.尝试了一些 Wordpress 插件,但一点用处都没有。

add_action( 'template_redirect', 'my_search_404' );
function my_search_404() {
    if ( is_search() && !isset($_SERVER['HTTP_REFERER'])) {
        wp_die( '404: Page not found', '404: Page not found', array( 'response' => 404 ) );
    }
}

But you need to consider a good security plugin, this is not enough for a large spam attack.但是你需要考虑一个好的安全插件,这对于大型垃圾邮件攻击来说是不够的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM