2014-10-07 89 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脚本执行。

相关问题