2015-05-18 83 views
0

我有一個域domain.com它被重寫到subdomain.domain.com/Home/Index通過.htaccess時沒有給出子域。robots.txt與Zend2和htaccess重寫規則

這是 - 當然 - 不是服務器文件系統中的文件,而是路由。該頁面是用Zend2構建的。

有沒有可能是一個履帶沒有找到robots.txt,位於public/robots.txt或ubdomain.domain.com/robots.txt`因爲這個轉發的?

抓取工具如何工作以抓取robots.txt?

+0

如果你不想爬蟲找到的robots.txt ...爲什麼你創建一個,然後? .htaccess(教程中的默認值)將重定向排除* .txt或* .css文件,並直接提供它們! – ThaDafinser

+0

我希望他們能夠找到它,但似乎有些抓取工具會將頁面編入索引。這就是爲什麼我問這是否可能。 – Corni

+0

爬蟲將索引「正常」頁面(來自ZF2的您的路線)。 Robots.txt只是它們應該包含/排除的指令(但是robots.txt永遠不會是抓取工具的頁面) – ThaDafinser

回答

0

您可以通過創建路由器來解決此問題。我參考了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 
    } 
}