我在路上看到这样的照片:
/0/1/2/3/4/01234/screenshots/1.jpg
访问它的URL如下所示:
/static/0/1/2/3/4/01234/screenshots/1.jpg
我想看起来像这样:
/0/1/2/3/4/01234/a-desc-of-the-picture/screenshots/1.jpg
或类似的东西。 目标是在SEO中的关键字。
但是想告诉nginx服务
/0/1/2/3/4/01234/screenshots/1.jpg
当他看到:
/0/1/2/3/4/01234/a-desc-of-the-picture/screenshots/1.jpg
我不希望它将用户redirect到正确的URL,我只是希望它在内部做映射。
可能吗 ? 我怎样才能做到这一点?
我在这里看到类似的东西 ,但是我找不到适用于我的案例的方法。 一些友好的小吃将不胜感激。
假设你已经有了一个正则expression式的基础path,你可以这样做:
location ~ ^/static/(././././.....)/[^/]+/(.*)$ { alias /location/on/filesystem/$1/$2; }
Nginx的别名指令比Apache的相当灵活。