Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
.htaccess 如何禁止所有文件&;文件夹并允许在robots.txt中使用一些?_.htaccess_Robots.txt - Fatal编程技术网

.htaccess 如何禁止所有文件&;文件夹并允许在robots.txt中使用一些?

.htaccess 如何禁止所有文件&;文件夹并允许在robots.txt中使用一些?,.htaccess,robots.txt,.htaccess,Robots.txt,我需要robots.txt 不允许所有文件和文件夹 只允许index.php&msub.php 我编辑了msub.php的链接,我从.htaccess中重写了的链接,如下所示: domain.com/p/subject122 domain.com/p/subject104 所以我想让这些链接像:domain.com/p/subject122一样出现在搜索引擎中 我该怎么做 我尝试过这个命令,但效果不太好。。链接:domain.com/p/subject104不会出现在搜索引擎中 User-age

我需要
robots.txt

  • 不允许所有文件和文件夹
  • 只允许
    index.php
    &
    msub.php
  • 我编辑了
    msub.php
    的链接,我从
    .htaccess
    中重写了
    的链接,如下所示:

    domain.com/p/subject122

    domain.com/p/subject104

    所以我想让这些链接像:domain.com/p/subject122一样出现在搜索引擎中

    我该怎么做

    我尝试过这个命令,但效果不太好。。链接:
    domain.com/p/subject104
    不会出现在搜索引擎中

    User-agent: *
    Disallow: /
    Allow: /index.php
    Allow: /msub.php
    
    .htaccess

    Options -Indexes
    
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    
    RewriteCond %{REQUEST_URI} ^/404/$
    RewriteRule ^(.*)$ /error.html [L]
    
    RewriteRule home /index.php 
    RewriteRule p/(.*)$ msub.php?page=$1
    

    robots.txt
    应该包含爬虫程序可以看到的URI,无论您在内部如何处理它们。因此,您的
    robots.txt
    应该具有:

    User-agent: *
    Disallow: /
    Allow: /p/subject122
    Allow: /p/subject104
    
    您的.htaccess也可以重构:

    Options -Indexes
    
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
    
    RewriteRule ^404/?$$ error.html [L,NC]
    
    RewriteRule ^home/?$ index.php [L,NC]
    
    RewriteRule p/(.*)$ msub.php?page=$1 [L,NC,QSA]
    

    你能在问题中显示你的完整.htaccess吗?是的,当然……这个问题似乎是离题的,因为它是关于SEO的,而SEO在堆栈溢出时是离题的。请阅读以更好地理解什么时候可以在这里问SEO问题(大多数不是),以及在哪里可以获得帮助。这是行不通的,因为URL是动态的而不是静态的,我无法手动将URL添加到robots.txt。在这种情况下,为什么还要为robots文件操心呢。现代搜索引擎足够聪明,只要你是对的,就可以缓存有效的URL。。搜索引擎可以捕获它,但是主机中的其他私有文件呢!?它也会在搜索中显示,这就是问题不,私有文件永远不会被搜索引擎缓存。请理解网络爬虫是如何工作的。他们将跟踪您网站根页面的链接。如果你在整个网站上发布了5个链接,那么搜索引擎将只缓存这5个URL。我有我没有发布的.txt文件,或者在我的网站或任何其他网页上使用它。。。我很震惊,谷歌搜索结果中居然有这样的内容!谷歌搜索引擎是如何捕获的?那些文件是私人的,我不想分享!