1

如果人们尝试在 Wordpress 中使用我的搜索表单来搜索粗俗或成人字词,我已获得重定向页面的代码。

我这样做的原因是因为谷歌可以禁止人们使用 Adsense,即使是在任何 URL 中使用粗鲁的话,即使是那些由搜索功能生成的。

这是我从 Google 收到的消息:

“广告服务已被禁用:examplesite.com

发生违规的示例页面:http ://examplesite.com/?s=somekeyword+tv+sex "

我已提出上诉,但我需要将访问重定向到我网站上的任何其他此类搜索,因为搜索会生成 URL,然后 Google 会将其编入索引。

我已经尝试了这个脚本,但将它插入到我的 Wordpress search.php 中,但我收到了这个错误:

解析错误:语法错误,意外的 ';' 在第 83 行的 /home/name/public_html/sitename.com/wp-content/themes/heatmap-adsense-theme/search.php

第 83 行引用以下代码: if($pageURL;

完整代码如下:

    <?php
   function curPageURL() {
   $pageURL = 'http';
   if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
   $pageURL .= "://";
   if ($_SERVER["SERVER_PORT"] != "80") {
   $pageURL .= 

   $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     } else {
      $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }
     if($pageURL;
     $string = "/sex/";

     if (preg_match_all($string, $pageURL, &$matches)) {
          header("Location: http://www.example.com/"); /* Redirect browser */
      }
   }
   ?>

代码看起来很完整,但请有人帮我解决这个错误以及之后的任何问题。

提前致谢。

PS:对不起,如果这是消息格式错误。尽我所能,但看不到任何预览按钮。

4

4 回答 4

7

我很确定如果您使用 404 或 410 Gone 标题,您可以告诉谷歌不要索引该页面,因此当使用特定关键字搜索词时,会在其中弹出该额外标题,或者只是重定向到警告页面。

如果您想使用 PHP 而没有正则表达式:

<?php 
$bad_words = array('some','bad','words','sex');

foreach($bad_words as $bad_word){
    if(stristr($_SERVER["REQUEST_URI"], $bad_word) !== false) {
        exit(header("Location: http://www.example.com/"));
        //exit(header("HTTP/1.0 410 Gone"));
    }
}
?>
于 2012-09-22T23:02:20.660 回答
0

我建议通过服务器配置使用重定向:

#.htaccess
RewriteEngine On
RewriteCond %{QUERY_STRING} (place|bad|words|here) [NC]
RewriteRule ^(.*)$ http://www.example.com/? [R=302,L]
于 2012-09-22T22:53:24.267 回答
0

上面的脚本似乎有一个错误:

if($pageURL;
 $string = "/sex/";

这应该被删除,因为以下 if 语句正在执行正则表达式匹配。

于 2012-09-22T22:58:55.533 回答
0

这对我来说效果最好。

<?php $bad_words = array('some','bad','words','sex'); foreach($bad_words as $bad_word){ if(stristr($_SERVER["REQUEST_URI"], $bad_word) !== false) { echo "Have a nice weekend!"; } else { echo "Have a nice day!"; } } ?>
于 2016-05-09T23:47:04.973 回答