检查网址是否包含单词
问题描述:
如何检查网址 - http://www.hotek.com.ua/live/5605/forum15000/223,http://www.hotek.com.ua/5635/forum12200/223是否包含单词'live'和'forum'。检查网址是否包含单词
我正在尝试这个(像这里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未找到或NOINDEX或301永久移动到主画面只是删除谷歌索引这些网页。
答
试试这个:
strpos - 返回将针存在相对草垛字符串的开头(独立的偏移量)的位置。此外 注意,使用字符串位置从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();
}
+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未找到或NOINDEX或301永久移动到主要的 页面只是为了从Google索引中删除这些页面。
你也可以要求Google将要删除的网址:
https://www.google.com/webmasters/tools/url-removal
参考文献:
难道只是你应该使用' &&'在你的情况下而不是'||'? – moopet
究竟什么不行?你说这没有帮助,但不是问题究竟是什么,也就是说你的预期和发生了什么。 – CherryDT