检查网址是否包含单词

时间:2016-04-26 15:17:45

标签: php url

如何查看网址 - http://www.hotek.com.ua/live/5605/forum15000/223http://www.hotek.com.ua/5635/forum12200/223是否包含“生活”字样。和'论坛'。

我试试这个(就像这里Check if url contains certain word then display)但它没有帮助。

$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

if ((strpos($url, 'forum') !== false) or (strpos($url, 'live') !== false)){

 header('HTTP/1.0 404 Not Found');

 echo "404 Not Found";

 exit();  
}

我需要404 Not Found或noindex或301永久移至主页只是为了从Google索引中删除这些页面。

2 个答案:

答案 0 :(得分:0)

试试这个:

  

strpos - 返回针存在于相对于haystack字符串开头的位置(与offset无关)。也   请注意,字符串位置从0开始,而不是1。

$str1 = "http://www.hotek.com.ua/live/5605/forum15000/223";
$str2 = "http://www.hotek.com.ua/5635/forum12200/223";

if(strpos($str1, "live") > 0 || strpos($str1, "forum") > 0 ){
    header('HTTP/1.0 404 Not Found');
    echo "404 Not Found";
    exit();  
}

答案 1 :(得分:0)

您可以尝试:

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if (preg_match('/forum|live/i', $actual_link)) {
    header('HTTP/1.0 404 Not Found');
    //you cannot echo anything else after header or you'll get an error
    exit();
}
  

我需要404 Not Found或noindex或301永久移动到主要   页面只是为了从Google索引中删除这些页面。

您还可以通过转到:

要求Google删除网址

https://www.google.com/webmasters/tools/url-removal

参考文献:

https://support.google.com/webmasters/answer/1663419?hl=en

相关问题