Search code examples
phpgeturl-encoding

Can't access static files with a URL-encoding characters in the names


On my CDN, I have some old files with names that were created using rawurlencode function. E.g. one of the files has this name:

Cat%20presentation.pdf

Now, when I try to read this file, I get a "File not found" error:

GET cdn.example.com/documents/Cat%20presentation.pdf

I believe that's because of the encoded space character in the name - %20. For the browser (and the CDN) what I'm asking for is this:

Cat presentation.pdf

while the "%20" part is actually in the filename.

Is there any way I can get around this and access the file?


Solution

  • You need to URL-encode the "%" character into "%25":

    GET cdn.example.com/documents/Cat%2520presentation.pdf
    

    But if I were you I'd just fix their filenames instead.