我在一条看起来像这样的路径上有图片:
/0/1/2/3/4/01234/screenshots/1.jpg
Run Code Online (Sandbox Code Playgroud)
访问它的 URL 如下所示:
/static/0/1/2/3/4/01234/screenshots/1.jpg
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像这样:
/0/1/2/3/4/01234/a-desc-of-the-picture/screenshots/1.jpg
Run Code Online (Sandbox Code Playgroud)
或者类似的东西。目标是在 SEO 的 URL 中包含关键字。
但是想告诉nginx服务
/0/1/2/3/4/01234/screenshots/1.jpg
Run Code Online (Sandbox Code Playgroud)
当他看到:
/0/1/2/3/4/01234/a-desc-of-the-picture/screenshots/1.jpg
Run Code Online (Sandbox Code Playgroud)
我不希望它将用户重定向到正确的 URL,我只希望它在内部进行映射。
是否可以 ?我怎样才能做到这一点?
假设您有一个可正则表达式的基本路径,您可以执行以下操作:
location ~ ^/static/(././././.....)/[^/]+/(.*)$ {
alias /location/on/filesystem/$1/$2;
}
Run Code Online (Sandbox Code Playgroud)