Operating system: Ubuntu 18.04.5 LTS
OS version: 18.04.5
Server version: Apache/2.4.29 (Ubuntu)
I have a file in a subdirectory and .htaccess in the site root. When I put
deny from all
to .htaccess it results into 403 error. When I put
AddDefaultCharset UTF-8
to .htaccess nothing happens.
Services->Configure Website->Edit directives shows
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Also I have found out that this depends on a file extension. When I request *.txt file the server responds with
Content-Type: text/plain; charset=UTF-8
But when I request a *.25PsG32KwC1VhKrWzgnKQu file it doesn’t sends a content-type probably because AddDefaultCharset Directive Description: Default charset parameter to be added when a response content-type is text/plain
or text/html
And *.25PsG32KwC1VhKrWzgnKQu does not have that mime type. And I can’t set the mime type for *.25PsG32KwC1VhKrWzgnKQu because the extension is random every time and AddType directive does not have a wildcard.
So I’ve replaced AddDefaultCharset with
Header add Content-Type "text/plain; charset=UTF-8"
directive and now the server responds
HTTP/1.1 500 Internal Server Error
for any request.
And that is because mod_headers is turned off by default so I entered ssh as root and typed
a2enmod headers
systemctl restart apache2
which got me to the point when *.25PsG32KwC1VhKrWzgnKQu file responds with
Content-Type: text/plain; charset=UTF-8
and *.txt file with only
Content-Type: text/plain
for no freaking reason.
But it kinda solved my problem anyway and I don’t know why. Now I can actually see the UTF-8 encoding opening *.25PsG32KwC1VhKrWzgnKQu and *.txt files in a browser and it still correctly handles *.zip files because it replaces the header with
Content-Type: application/zip
despite of the header directive
Header add Content-Type "text/plain; charset=UTF-8"
although it’s still there.
Now I have added AddDefaultCharset to the .htaccess
AddDefaultCharset UTF-8
Header add Content-Type "text/plain; charset=UTF-8"
and the server responds absolutely correctly with the right encoding to every request but I’m disgusted with what have I done so please feel free to delete this post so no one will never ever have to witness this abomination.