nginx - nginx 服务器:如何从 URL 中删除第一个目录
问题描述
有人可以帮我从 URL 中删除第一个目录名称吗?
我的图像位置是_data/hotel/3/15377/hotel_image.jpg
但是图像路径由于代码中的相对 URL 而发生了变化,它变成了这样的东西。
example.com/france/_data/hotel/3/15377/hotel_image.jpg
example.com/usa/_data/hotel/3/15377/hotel_image.jpg
example.com/india/_data/hotel/3/15377/hotel_image.jpg
他们是否有可能从上述 URL 中删除动态国家名称
解决方案
如果你只想重写这个特定的 URL,你可以location
在你的配置中使用这个块:
location ~ /[a-z]+/_data/hotel/3/15377/hotel_image.jpg {
try_files /_data/hotel/3/15377/hotel_image.jpg;
}
如果要重写所有导致 的 URL /<country>/_data/...
,可以使用:
location ~ /[a-z]+/_data/(.+) {
try_files /_data/$1;
}
或进行更严格的 URL 检查:
location ~ /(?:france|usa|india)/_data/(.+) {
try_files /_data/$1;
}
推荐阅读
- docker - 入口点#FAIL - 没有这样的文件或目录
- bluetooth - 在客户端设备上要求/实施蓝牙密码密码
- typescript - 阻止 Visual Studio Code 在 .ts 文件中自动添加分号和单引号
- flutter - How to show list of only the completed items?
- javascript - NodeJS 从另一个窗口获取像素颜色
- instagram - 如何从 instagram 嵌入帖子中获取个人资料图片 URL?
- java - 运行最新的 Jetty 版本会破坏我的构建
- mongodb - Docker 构建失败并显示“包 'mongodb' 没有安装候选者”
- javascript - 无论如何设置一个变量等于每次访问变量时调用的函数
- node.js - 为什么我收到的 jwt 格式错误?