gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
nginx 匹配/pc/storage/topic/63eaf82d28f50.jpg200200 地址重写为/index?s=thumb
- User
nginx 匹配/pc/storage/topic/63eaf82d28f50.jpg_200_200 地址重写为/index?s=thumb
- Assistant
在nginx的配置文件中添加以下代码实现重写:
codelocation /pc/storage/topic/ { rewrite ^/pc/storage/topic/(.*)_\d+_\d+.jpg$ /index?s=thumb break; # ... }这样,访问
/pc/storage/topic/63eaf82d28f50.jpg_200_200就会被重定向到/index?s=thumb页面。其中^/pc/storage/topic/(.*)_\d+_\d+.jpg$是匹配原始URL的正则表达式,$1表示匹配成功后的第一个子模式,即图片的名字,\d+表示至少一个数字,因此\d+_\d+表示图片尺寸,将被忽略。 - User
用nginx 匹配/pc/storage/topic/63eaf82d28f50.jpg_200_200 地址重写为/index?s=thumb
- Assistant
在nginx的配置文件中添加以下代码实现重写:
codelocation /pc/storage/topic/ { if ($request_uri ~ "^/pc/storage/topic/(.*)_\d+_\d+.jpg$") { rewrite ^(.*)$ /index?s=thumb break; } # ... }这样,访问
/pc/storage/topic/63eaf82d28f50.jpg_200_200就会被重定向到/index?s=thumb页面。其中^/pc/storage/topic/(.*)_\d+_\d+.jpg$是匹配原始URL的正则表达式,\d+表示至少一个数字,因此\d+_\d+表示图片尺寸,将被忽略。$1表示匹配成功后的第一个子模式,即图片的名字。if语句用于判断请求的URL是否符合条件,如果符合,则使用rewrite语句进行重写。