简体   繁体   English

网址重写和robots.txt

[英]URL rewrite and robots.txt

I have made urls SEO friendly ie 我已经使网址SEO友好,即

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

Previously, the url of the above page was 以前,以上页面的网址是

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

Now Google is still showing the second URL in the search results. 现在,Google仍在搜索结果中显示第二个URL。 My question is that if i disallow /search in robots.txt , will Google stop crawling that page altogether or it will still crawl mydomain.com/topic/title-of-page ie the new URL? 我的问题是,如果我不允许/search in robots.txt ,Google会完全停止对该页面的爬网,还是仍将对mydomain.com/topic/title-of-page即新URL)进行爬网?

Thanks a lot for your help. 非常感谢你的帮助。 Sorry for the spaces in the URL as SO wouldn't let me post them 抱歉,URL中的空格无法让我发布它们

Seb 塞布

You'll want to fix this right away. 您将要立即修复此问题。 There are going to be issues with duplicated content on the site in regard to SEO. 有关SEO的网站上的重复内容将会出现问题。

To cut half of the search engine traffic from your site, add this to your robots.txt file: 要减少来自您网站的搜索引擎流量的一半,请将其添加到robots.txt文件中:

User-agent: *
Disallow: /search.php

That way none of the search engines will mine the old link. 这样,所有搜索引擎都不会挖掘旧链接。 They may still have it cached for their search results. 他们可能仍将其缓存为搜索结果。 That being said you'll need to handle each of the pages they serve with a 301 redirect so you're not penalized. 话虽这么说,您需要使用301重定向处理它们提供的每个页面,因此您不会受到损失。 This will tell them to update their cache. 这将告诉他们更新其缓存。

Additionally you'll want to add a sitemap.xml file that contains all for the proper URLs on the server in order of priority. 此外,您将需要添加一个sitemap.xml文件,该文件按优先级顺序包含服务器上所有正确URL的文件。

Assuming you have the new path stored in the DB, you'll need to do something like this to search.php . 假设您将新路径存储在数据库中,则需要对search.php执行类似的操作。 That way you can keep your URLs for SEO. 这样,您可以保留SEO的URL。 301 is a Permanent Redirect. 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();
  } 
}

Otherwise you could replace the second query with the function you're using to build the paths. 否则,您可以将第二个查询替换为用于构建路径的函数。

You could add something to the .htaccess file like this for every entry, but it's not future proof and the larger the list, the longer to process (more server overhead). 您可以为每个条目向.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]

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

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