At times, there are differences between your local or staging and production environment in handling URL encodings. In strict environments (likely production), HTML links to files with encoded characters in their file name will result to a 403 (not found) error. Therefore, you must rename the file names in your directory.
Install rename utility
In MacOS, use homebrew to install the rename utility.
$ brew install rename
Find and rename files
- Open the terminal app
- Change to the directory of your project
$ cd [path/to/directory]
- Find (recursively) and rename files in the directory using the pattern and replacement
$ find . -iname "*[pattern]*" -exec rename -f -n 's/[pattern]/[replacement]/g' '{}' \;
$ find . -iname "*%20*" -exec rename -f -n 's/%20/ /g' '{}' \;
Rename switches
-f - Force renaming files (overwrite if exists)
-n - Dry run or print results of renaming
Enter rename --man to see full list of switches and how to use.
Add new comment