I have a website where users can upload files, if they upload a file with a special character in the filename, the filename will be encoded (for example: iordănescu.pdf
will become iord%C4%83nescu.pdf
)
This causes some problems to be able to open these files from a link on the website. The CMS provides a link like this one: example.com/frontend/files/jobs/iord%C4%83nescu.pdf
.
But it only works when the encoded filename is encoded (so double encoded) like this: example.com/frontend/files/jobs/iord%25C4%2583nescu.pdf
.
Can I write a rule in my .htaccess
file to make the filenames double encoded? Or is there something else I can try?
I've updated my current .htaccess
file, which is saved in the same folder where the files are uploaded to, to the suggestion of MrWhite:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} "^GET /(.*%.*) HTTP/"
RewriteRule \.(pdf|jpg|png)$ /%1 [B,L]
This now gives me the following error:
The requested URL /frontend/files/jobs/iord%C4%83nescu.pdf was not found on this server.
Which is how I see the file via FTP, but if I copy the path via FTP it appears to be double encoded already:
/www/frontend/files/jobs/iord%25C4%2583nescu.pdf
Side note:
This website has been developed by someone else and is rather old. I am now responsible for maintaining this website and the client informed me about this issue. Since this website will be completely redone soon I don't want to spend too much time on creating a fix so being able to solve it via .htaccess
would be ideal.
.htaccess
file? The requested URL stated does not appear to match the directive in the.htaccess
file you posted? And you state the.htaccess
file is in the "folder where the files are uploaded", yet you are still referring to a long URL path in the directive? The directive also references a "language code" that is not present in the URL stated?