简体   繁体   中英

nginx - rewrite rule for URL with different cases and encoded spaces

Deploying a brand new version of a portal I have to add some "legacy" rewrites in order to redirect all the past document links to their new versions.

A couple of those old links are like

http://sitename.com/media/pdf/MIXED%20FIL_E_Name_With%20spaces_and%20stuff-e324a.pdf

while their new path is

https://sitename.it/app/uploads/2019/03/mixed-fil_e_name-with-spaces_and-stuff-e324a.pdf .

I tried the following rewrites to no avail.

rewrite ^/media/pdf/MIXED%20FIL_E_Name_With%20spaces_and%20stuff-e324a.pdf(.*) /app/uploads/2019/03/mixed-fil_e_name-with-spaces_and-stuff-e324a.pdf permanent;

rewrite ^/media/pdf/MIXED\%20FIL_E_Name_With\%20spaces_and\%20stuff-e324a.pdf(.*) /app/uploads/2019/03/mixed-fil_e_name-with-spaces_and-stuff-e324a.pdf permanent;

rewrite ^/media/pdf/MIXED\\\%20FIL_E_Name_With\\\%20spaces_and\\\%20stuff-e324a.pdf(.*) /app/uploads/2019/03/mixed-fil_e_name-with-spaces_and-stuff-e324a.pdf permanent;

What am I missing?

The rewrite and location directives use a normalised URI. The reserved characters have already been decoded. Use a literal space instead of %20 , but enclose the expression in quotes.

For example:

rewrite "^/media/pdf/MIXED FIL_E_Name_With spaces_and stuff-e324a.pdf" /app/uploads/2019/03/mixed-fil_e_name-with-spaces_and-stuff-e324a.pdf permanent;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM