For some reason, I want to serve my robots.txt through a PHP script. I have apache setup, so the robots.txt file request (infact all file requests) comes to one PHP script.
The code I use to render robots.txt is:
echo "User-agent: wget\n"; echo "Disallow: /\n";
However, it does not process newlines. How to download a robots.txt file correctly so that search engines (or any client) see it correctly? Should I send special headers for txt files?
EDIT 1:
Now I have the following code:
header("Content-Type: text/plain"); echo "User-agent: wget\n"; echo "Disallow: /\n";
which still does not display newline characters (see http://sarcastic-quotes.com/robots.txt ).
EDIT 2:
Some people have noted that this is just fine and does not appear in the browser. It was just curious how it looks right: http://en.wikipedia.org/robots.txt
EDIT 3:
I downloaded both mine and Wikipedia via wget, and I see the following:
$ file en.wikipedia.org/robots.txt en.wikipedia.org/robots.txt: UTF-8 Unicode English text $ file sarcastic-quotes.com/robots.txt sarcastic-quotes.com/robots.txt: ASCII text
FINAL SUMMARY:
The main problem: I did not configure the header. However, there is another internal error that creates a Content-Type as html. (this is because my request is actually served through an internal proxy, but this is another problem).
Some comments that browsers do not display a new line were only half correct. → modern browsers correctly display a new line if the content type is text / simple. I choose an answer that exactly matches the real problem and was devoid of the above slightly misleading misconception :). Thank you all for your help and your time!
thanks
In JP
php text header robots.txt plaintext
JP19
source share