[英]Nginx rewrite : how to remove everything after extension of a file
There are a lot of bad request of images and files on my site... but with names close from the real name. 我的网站上有很多关于图像和文件的错误请求......但名称与真实姓名相近。 basically, if i have a file called example.gif, there is a call to example.gifzerzer.
基本上,如果我有一个名为example.gif的文件,则会调用example.gifzerzer。 What i want is to rewrite to keep the name and the extension, but nothing after it.
我想要的是重写以保留名称和扩展名,但之后没有任何内容。
I did create a map file with rewrite (it's working for example the tmp.php to index.php rewrite below except the rule for removing everything after extension). 我确实创建了一个带有重写的映射文件(例如,它正在使用tmp.php到index.php重写,除了扩展后删除所有内容的规则)。
Here is what i've done so far : 这是我到目前为止所做的:
/(.+\.(bmp|gif|ico|jpeg|jpg|png|svg)).+ /$1;
this is not working neither 这两个都不起作用
/(.+\.(bmp|gif|ico|jpeg|jpg|png|svg)).+? /$1;
my map : 我的地图:
map $request_uri $redirect_uri {
default "";
/(.+\.(bmp|gif|ico|jpeg|jpg|png|svg)).+ /$1;
/tmp.php /index.php;
}
i was under Apache before migrating to Nginx and this was working : 在迁移到Nginx之前,我在Apache之下,这是有效的:
RewriteRule ^([a-z0-9\-/_]*\.(bmp|gif|ico|jpeg|jpg|png|svg)).+ /$1 [R=301,L]
I did that rewrite that is working, when put in the server section, but then it is not included in the map. 当我放入服务器部分时,我做了那个有效的重写,但是它没有包含在地图中。
location ~ (.+\.(bmp|gif|ico|jpeg|jpg|png|svg)).+$ {
return 301 /$1;
}
if someone has an idea why, or can confirm that i'm doing it right ? 如果有人知道为什么,或者可以确认我做得对吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.