WordPress isn’t doing this, those files are served by the server underneath WordPress, aka Nginx/Apache/etc. This is because there’s a cost to loading WordPress and you don’t want to pay that cost for assets such as JPEG’s or other files in the uploads folder, it’s much faster to let Apache/Nginx do it as that’s something they’ve been optimised for.
why not .txt files?
Because you’re a WordPress.com customer:
WP.com has configured their servers not to serve plaintext files as a security measure.
Is WordPress.com not WordPress?
No, WP.com is a 3rd party host that hosts WordPress sites. Its main differentiator is that it has access to the trademarks and is ran by the founder, but the software it runs isn’t quite the same as what everybody else is running.
WordPress.com has a lot of additional restrictions, features, and quirks intended to make it more secure and scale better. Partially because it used to be one gigantic multisite installation. One of these differences will be stopping displaying arbitrary text files which could be used for malicious purposes.
Most WordPress sites do not run on WordPress.com
Resolving This
You’ll need to speak with their support to resolve this, though there’s a high chance they’ll say that it is not possible. Moving to an alternate host is also an option.
E.g. I was able to upload and serve a plaintext file on my host (a VPS):
https://tomjn.com/wp-content/uploads/2024/02/wordpress-text-files.txt
The edge case
For completeness sake should someone else be reading this, the one scenario where WordPress does serve these files is ms-files.php
. If your direct URL to the text file references ms-files.php
then WordPress is responsible, however this requires that you have multisite setup, and have configured WordPress to use this file.
In the case of a WordPress.com site, this is extremely unlikely, and virtually impossible on anything newer than 10 years old. If you do not see ms-files.php
in the URL then this is not happening.