A
A
Anton Teremshonok2015-02-12 11:53:15
Nginx
Anton Teremshonok, 2015-02-12 11:53:15

How to make a redirect in nginx using rewrite?

There is a task to make a request redirect to nginx.
There is a link:
http://site_name/dl/filename.exe
It is necessary that when requesting:
http://site_name/dl/filename2.exe
where the number 2 is any Latin letter (large or small) or a number, and everything leads to the same file filename.exe
Also, instead of a specific filename.exe, there can be any other name, for example filenamedistrib.exe and should be accessible by the same rules.
I tried to do as indicated here: How to correctly compose rewrite in nginx?
I did this, but it doesn't work:
rewrite ^/([a-zA-Z0-9\-]+)\.exe$ /dl/$1.exe last;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Teremshonok, 2015-02-13
@TerAnYu

After a long googling, reading, something came up:
A more detailed task appeared a little later, which pleased such a design.
- there are files on the disk (ProgrammSetup.exe / ProgrammSetup_1.exe), it is necessary that they be available both by their own name and by any name, according to the rule:
1. ProgrammSetupC.exe / ProgrammSetupO.exe / ProgrammSetupY.exe / ProgrammSetupS .exe / ProgrammSetupF.exe / ProgrammSetupI.exe -> ProgrammSetup.exe
2. ProgrammSetupC_1.exe -> ProgrammSetup.exe
3. ProgrammSetupO_2.exe / ProgrammSetupY_3.exe / ProgrammSetupS_4.exe / ProgrammSetupF_5.exe / ProgrammSetupI_6.exe -> ProgrammSetup. exe
4. ProgrammSetup_1.exe -> ProgrammSetup_1.exe
5. ProgrammSetup_2.exe -> ProgrammSetup.exe
Maybe where I made a mistake in the requirements, but this is quite satisfactory.

D
Dmitry Polushkin, 2015-02-13
@dmitry-polushkin

rewrite ^/dl/filename[a-zA-Z0-9\-]+\.exe$ /dl/filename.exe last;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question