0

I'm having trouble setting up the redirects for a Magento extension. The URL requested is:

example.com/index.php/Cdiscount/Package/download/type/offers/filename/BMS_PREFIX_161d529d7c3ef4b5ae1dca92e2334de6/BMS_PREFIX_161d529d7c3ef4b5ae1dca92e2334de6.zip

but nginx should return:

example.com/index.php/Cdiscount/Package/download/type/offers/filename/BMS_PREFIX_161d529d7c3ef4b5ae1dca92e2334de6 

instead.

The part between BMS_PREFIX_ and .zip will often change, so this should probably fetch all .zip file requests in the offers/ location. I am not 100% sure if the filename in offers/filename/BMS_PREFIX... is configurable to be something else or changes per request, but I assume that it won't change.

So basically I need to tell Nginx to reply with example.com/path/ when a request for example.com/path/path.zip is requested.

current config:

location / {
    proxy_pass http://127.0.0.1:6081;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    #proxy_hide_header X-Varnish;
    proxy_hide_header Via;
    proxy_hide_header Vary;
    proxy_hide_header X-Server;
    proxy_hide_header X-Backend-Server;
    proxy_hide_header X-Frame-Options;
    proxy_redirect off;
    proxy_max_temp_file_size 0;
    proxy_connect_timeout      7200;
    proxy_send_timeout         7200;
    proxy_read_timeout         7200;
    proxy_buffer_size          256k;
    proxy_buffers              4 512k;
    proxy_busy_buffers_size    512k;
    proxy_temp_file_write_size 512k;
}
masegaloeh
  • 18,236
  • 10
  • 57
  • 106
dawns
  • 1
  • 3

1 Answers1

1

Maybe you mean something like this

rewrite ^(/index\.php/Cdiscount/Package/download/type/offers/filename/BMS_PREFIX_)(.+?)/BMS_PREFIX_(.+).zip $1$2;

Add above line before proxy_pass statement.

Notes:

  • To check the rewrite is working, either setup request logging at Magento or you can use rewrite_log by nginx
  • This rewrite doesn't check whether BMS_PREFIX after filename and BMS_PREFIX before .zip is same string. In other words, request example.com/path/otherpath.zip will still rewritten to to example.com/path
  • For explanation of that regex scheme, see here.
masegaloeh
  • 18,236
  • 10
  • 57
  • 106