URL rewrite and robots.txt


URL rewrite and robots.txt

我已经使url SEO友好,即

http://mydomain.com/topic/title-of-page

之前,上面页面的url是

http://mydomain.com/search?id=6567889

现在Google仍然在搜索结果中显示第二个URL。我的问题是,如果我在robots.txt中不允许/search,谷歌会完全停止抓取该页面还是仍然会抓取mydomain.com/topic/title-of-page,即新的URL?

非常感谢你的帮助。很抱歉URL中有空格,所以不允许我发布 Seb

您将需要立即修复此问题。在SEO方面,网站上的重复内容将会出现问题。

如果想要减少一半的搜索引擎流量,请将以下内容添加到robots.txt文件中:

User-agent: *
Disallow: /search.php

这样没有搜索引擎会挖掘旧链接。他们可能还把它缓存在搜索结果里。也就是说,你需要用301重定向处理他们提供的每个页面,这样你就不会受到惩罚。这将告诉他们更新缓存。

此外,您还需要添加一个sitemap.xml文件,其中包含服务器上按优先级顺序的所有适当url。

假设您在DB中存储了新路径,您需要对search.php执行类似的操作。这样你就可以为SEO保留你的url。301是永久重定向。

if(preg_match('!^/search!',$_SERVER['REQUEST_URI'])){
  $tempID = $_GET['id'];
  $tempID = mysqli_real_escape_string($tempID);
  $query = "select count(*) from table where id=$tempID";
  $count = mysqli_result(mysqli_query($db_link,$query),0);
if($count==1){
 $query2 = "select correctPath  from table where id=$tempID";
 $correctPath = mysqli_result(mysqli_query($db_link,$query2),0);
   header( "HTTP/1.1 301 Moved Permanently" );
   header( "Location: $correctPath" );
   exit();
  } else {
  //non-existent ID
   header( "HTTP/1.1 301 Moved Permanently" );
   header( "Location: /" );
   exit();
  } 
}

否则,您可以将第二个查询替换为用于构建路径的函数。

您可以像这样为每个条目添加一些内容到.htaccess文件中,但这不是未来的证明,并且列表越大,处理时间越长(服务器开销更多)。

RewriteEngine On
RewriteRule ^search'.php'?id=1  /page1_new_path/ [L,R=301]
RewriteRule ^search'.php'?id=2  /page2_new_path/ [L,R=301]