Forum Moderators: phranque

Message Too Old, No Replies

Setting .js to run PHP makes robots.txt type JScript?

         

JAB Creations

12:07 am on Jan 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Server: addon domain, unknown Apache version (headers only say Apache).

Domain: just a test domain that I use for testing.

Goal: ensure JavaScript files can execute PHP code.

Problem: when set the robots.txt file is served as JScript type.

I also want to log everything requesting robots.txt which I would need to use PHP with. When it doesn't ask to save the file as a JScript file it displays the PHP code in plain text.

robots.txt
<?php header('content-type:text/plain');?>
User-agent: *
Disallow: /


.htaccess
AddType application/x-httpd-php .css .html .js .txt .xml


Even if the only extension is .txt it keeps insisting that the text file has a JScript file type.

Could this be an Apache issue or possibly a php.ini setting? It's a different server that I haven't used before. This is all of the code with an empty parent .htaccess file in the main (non-addon) directory.

- John

g1smd

1:00 am on Jan 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There's another approach possible.

Put your PHP code in the "file" /robots.php. Ensure that external requests for the "URL" example.com/robots.php are blocked. Set up a rule such that when the "URL" example.com/robots.txt is requested, there is an internal rewrite to the "file" at /robots.php.