Files with special characters in their file name load locally but not live

43 Views Asked by At

I converted a Drupal website to a static site using sitesucker (Mac tool). I am running MAMP 6 locally. Some images are missing live, probably because of an encoding issue.

For instance, I have this file:

Akzeptanz_GoA3+_Vorschaubild_Symbolbild_pexels-jéshoots-253647.jpg

And both locally and live it is embedded exactly like this:

<img src="/path/Akzeptanz_GoA3+_Vorschaubild_Symbolbild_pexels-je%CC%81shoots-253647.jpg">

Locally the image works, Live it is 404. What could be the reasons and possible solutions to this different behaviour? Live is a regular LAMP stack.

This behavior consists when I empty both htaccess files.

1

There are 1 best solutions below

2
MrWhite On

"Fixing" the URL encoding in the HTML source would be the preferred solution, as mentioned in comments (from e%CC%81 to %C3%A9). (Or even "normalising" the filename, so URL-encoding is not an issue.)

However, if that is not an option then you could perhaps do a search/replace in .htaccess.

For example, near the top of the root .htaccess file:

# Replace "e%CC%81" with "%C3%A9"
RewriteCond %{THE_REQUEST} ^GET\s/(.*)e%CC%81([^\s]*)
RewriteRule ^path/ %1\%C3\%A9%2 [NE,L]

Include a /path/ in the RewriteRule pattern (as above) to limit the number of URLs tested.

We match (and capture) the requested URL in the preceding condition against THE_REQUEST server variable, which preserves the URL-encoded URL that was actually requested.

The literal % in the substitution string should be backslash-escaped to avoid potentially being interpreted as a backreference (although since they are not followed by a digit, that should be OK).


Chrome shows Akzeptanz_GoA3+_Vorschaubild_Symbolbild_pexels-jéshoots-253647.jpg in the address bar though. When I change it in the src attribute it stays like that and loads

Chrome will often show the more friendly URL-decoded URL in the address bar, even if the underlying request is URL-encoded.

When you change it in the src attribute (to the URL-decoded version I assume) then the browser automatically "fixes" it and URL-encodes the URL in the HTTP request (you can examine the Network traffic in the browser dev tools).