2014-10-07 84 views
0

我有以下.htaccess,我試圖在/public/robots.php中執行/robots.txt。 我嘗試不同的方法,但沒有執行我的PHP腳本...Zend Framework 1自定義robots.txt在.htaccess中

<IfModule mod_deflate.c> 
    AddOutputFilterByType DEFLATE text/css application/x-javascript application/javascript text/html text/plain text/xml text/json application/json 
</IfModule> 

SetEnv APPLICATION_ENV "development" 

php_flag magic_quotes_gpc off 
php_flag register_globals off 
php_flag short_open_tag on 

RewriteEngine on 
RewriteRule !\.(ico|js|css|jpeg|jpg|png|bmp|gif|pdf|doc|docx|xls|xlsx|xmlx|xml|pps|eml|txt|psd|flv|swf|fla|mp3|ttf|eot|svg|woff|zip)$ public/index.php [NC,L] 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteCond %{REQUEST_URI} !^/public/ 
RewriteRule ^(.*)$ public/$1 [L] 

我如何使用動態的robots.txt,執行/public/robots.php?

Thx!

+0

當您從瀏覽器請求/robots.txt時,您會得到什麼結果?特別是狀態碼和任何錯誤輸出?另外,如果直接請求/public/robots.php,會得到什麼結果? – plasticinsect 2014-10-07 19:54:02

+0

robots.txt返回404找不到。和robots.php返回'Mensagem:沒有路線匹配請求' – 2014-10-07 19:55:55

+0

我解決了這個問題,我會在這裏發佈我的解決方案 – 2014-10-07 19:59:21

回答

1

我解決了這個問題,這htaccess的:

<FilesMatch "^robots.txt$"> 
    ForceType application/x-httpd-php 
</FilesMatch> 

現在,我能夠執行公共/的robots.txt作爲PHP腳本。所以,在我的public/robots.txt文件中,我可以測試我正在使用的服務器並創建一個動態機器人。

現在,當訪問mysite.com/robots.txt時,輸出由public/robots.txt生成,並作爲PHP腳本執行。

相關問題