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,带有Zend2和htaccess重写规则_.htaccess_Redirect_Zend Framework2 - Fatal编程技术网

.htaccess robots.txt,带有Zend2和htaccess重写规则

.htaccess robots.txt,带有Zend2和htaccess重写规则,.htaccess,redirect,zend-framework2,.htaccess,Redirect,Zend Framework2,我有一个域domain.com,当没有给出子域时,它会通过.htaccess重写为subdomain.domain.com/Home/Index 当然,这不是服务器文件系统中的文件,而是路由。该页面是使用Zend2构建的 爬虫是否可能因为此转发而找不到位于public/robots.txt或ubdomain.domain.com/robots.txt`中的robots.txt 爬虫是如何获取robots.txt的 您可以通过创建路由器来解决此问题。以下解决方案请参考Matthew Weier O

我有一个域
domain.com
,当没有给出子域时,它会通过.htaccess重写为
subdomain.domain.com/Home/Index

当然,这不是服务器文件系统中的文件,而是路由。该页面是使用Zend2构建的

爬虫是否可能因为此转发而找不到位于
public/robots.txt
或ubdomain.domain.com/robots.txt`中的
robots.txt


爬虫是如何获取robots.txt的

您可以通过创建路由器来解决此问题。以下解决方案请参考Matthew Weier O'Phinney

$route = new Zend_Controller_Router_Route_Static(
    'robots.txt'
    array(
        'module'     => 'default',
        'controller' => 'index',
        'action'     => 'robots'
    )
);
$router->addRoute('robots.txt', $route);
然后,在IndexController中创建一个“robotsAction()”:

class IndexController extends Zend_Controller_Action
{
    // ...

    public function robotsAction()
    {
        // Set content-type header to text/plain
        $this->getResponse()->setHeader('Content-Type', 'text/plain');

        // perform some logic, add some variables to the view, and
        // you're done
    }
} 

如果你不想爬虫找到robots.txt…为什么要创建一个呢?.htaccess(教程中的默认值)将*.txt或*.css文件从重定向中排除,并直接为它们提供服务!我想让他们找到它,但似乎有些爬虫索引的网页。这就是为什么我问这是否可行的原因。爬虫程序将索引“正常”页面(来自ZF2的路由)。Robots.txt只是一个指示,告诉他们应该包含/排除哪些内容(但Robots.txt永远不是爬虫的页面),所以爬虫可以找到这个Robots.txt,即使有重写规则?如果你可以自己用浏览器访问subdomain.domain.com/Robots.txt…那么是的