Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php URL重写和robots.txt_Php_.htaccess_Url_Seo - Fatal编程技术网

Php URL重写和robots.txt

Php URL重写和robots.txt,php,.htaccess,url,seo,Php,.htaccess,Url,Seo,我已经使网址搜索引擎优化友好,即 http://mydomain.com/topic/title-of-page 以前,上面页面的url是 http://mydomain.com/search?id=6567889 现在谷歌还在搜索结果中显示第二个URL。我的问题是,如果我在robots.txt中不允许/search,谷歌会完全停止抓取该页面,还是仍会抓取mydomain.com/topic/title of page即新的URL 非常感谢你的帮助。很抱歉URL中有空格,所以不让我发布 Se

我已经使网址搜索引擎优化友好,即

http://mydomain.com/topic/title-of-page
以前,上面页面的url是

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

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


Seb

您需要立即修复此问题。在搜索引擎优化方面,网站上的重复内容将出现问题

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

User-agent: *
Disallow: /search.php
这样,没有一个搜索引擎会挖掘旧链接。他们可能仍将其缓存以用于搜索结果。也就是说,你需要用301重定向处理他们提供的每个页面,这样你就不会受到惩罚。这将告诉他们更新缓存

此外,您还需要添加一个sitemap.xml文件,该文件按优先级顺序包含服务器上正确URL的所有内容

假设新路径存储在数据库中,则需要执行类似以下操作来
search.php
。这样你就可以保留你的搜索引擎优化网址

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

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


如果设置了
$\u GET['id']
并且是有效的id,则可能需要创建301重定向(临时重定向)或302(永久重定向),否则为404。我不知道你如何处理SEO重写,但这应该给你一个开始。
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();
  } 
}
RewriteEngine On
RewriteRule ^search\.php\?id=1  /page1_new_path/ [L,R=301]
RewriteRule ^search\.php\?id=2  /page2_new_path/ [L,R=301]