Reputation: 436
I have the following .htaccess, and I'm trying to execute the /robots.txt in /public/robots.php. I tried different ways, but my php script was not being executed...
<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]
How can I use a dynamic robots.txt, executing the /public/robots.php ?
Thx!
Upvotes: 0
Views: 431
Reputation: 436
I fixed this problem with this htaccess:
<FilesMatch "^robots.txt$">
ForceType application/x-httpd-php
</FilesMatch>
Now, I'm able to execute the public/robots.txt as a php script. So, inside my public/robots.txt I'm able to test which server I'm using and create a dynamic robots.
Now when accessing the mysite.com/robots.txt the output is generated by public/robots.txt, executed as a PHP script.
Upvotes: 1