2014-02-28 28 views
5

我已經讓我的生活CakePHP的web應用程序如下:如何處理我的CakePHP應用程序的robots.txt?

2014-02-18 04:06:00 Error: [MissingControllerException] Controller class Robots.txtController could not be found. 
Exception Attributes: array (
    'class' => 'Robots.txtController', 
    'plugin' => NULL, 
) 
Request URL: /robots.txt 

我該怎麼辦?

我使用CakePHP 2.4.2

UPDATE:

這是我的robots.txt。還有什麼我應該補充的?我把它放在webroot

User-agent: * 
Disallow: /admin/ 
+0

我想你的虛擬主機的根目錄並不是指向app/webroot,而是指向app /。 – burzum

+0

實際上,我的webroot中甚至沒有robots.txt文件。我剛剛加了一個。看我更新的問題 –

回答

0

您可能需要編輯.htaccess文件(或/etc/lighttpd/lighttpd.conf或相似的,這取決於你正在使用的網絡服務器)忽略URL重寫爲/robots.txt的。您必須已經將您的Web服務器設置爲將請求傳遞給CakePHP,但遺憾的是它將請求robots.txt傳遞給CakePHP。您需要將Web服務器配置爲不重寫/robots.txt請求的url,而是改爲讀取文件的內容。請記住,我不知道nginx,但嘗試類似這樣的事情;我不知道nginx,但嘗試類似這樣的事情;我不知道,

server { 
    listen 80; 
    client_max_body_size 5M; 
    server_name example.com; 
    root /var/virtual/example.com/webroot; 
    include common.conf; 
    include php.conf; 

    if (!-e $request_filename) { 
     rewrite ^/(.+)$ /index.php?url=$1 last; 
     break; 
    } 
} 
+0

讓我告訴你我的nginx配置http://stackoverflow.com/questions/22093091/how-to-convert-www-example-com-posts-123-to-example-com-posts-123 –

4

您收到錯誤消息的原因是因爲Bot或其他軟件請求文件,而CakePHP找不到它,因爲它不存在。現在您已經創建了一個robots.txt文件,您不應該收到錯誤消息。您可以檢查這個自己,轉到:

http://www.example.com/robots.txt 

我可能會刪除/管理/,不想做廣告您的後端是!

就像在你的robots.txt文件下面一個簡單的文本應該是足夠的,刪除提及站點地圖,如果你沒有一個:

User-agent: * 
Disallow: 

Sitemap: http://www.example.com/sitemap.xml 

希望對您有所幫助。

7

將robots.txt複製到/app/webroot/目錄中。

相關問題