V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
zxc337
V2EX  ›  NGINX

nginx rewrite url 把后缀全改成 htm

  •  
  •   zxc337 · 2014-08-25 15:38:21 +08:00 · 4554 次点击
    这是一个创建于 3750 天前的主题,其中的信息可能已经有所发展或是发生改变。
    nginx rewrite url:
    问题,想把这种 url 改写成
    www.zuobian.com/tour/ --> www.zuobian.com/index.htm
    www.zuobian.com/tour/xxx --> www.zuobian.com/tour/xxx.htm
    www.zuobian.com/tour/xxx/ --> www.zuobian.com/tour/xxx.htm
    www.zuobian.com/tour/xxx. --> www.zuobian.com/tour/xxx.htm
    www.zuobian.com/tour/xxx.xxx --> www.zuobian.com/tour/xxx.htm
    www.zuobian.com/account/ --> www.zuobian.com/account/login.htm
    www.zuobian.com/account/home --> www.zuobian.com/account/home.htm
    www.zuobian.com/account/home.html --> www.zuobian.com/account/home.htm
    www.zuobian.com/account/home.xxx --> www.zuobian.com/account/home.htm
    www.zuobian.com/account/home. --> www.zuobian.com/account/home.htm
    www.zuobian.com/account/home --> www.zuobian.com/account/home.htm
    www.zuobian.com/account/home/ --> www.zuobian.com/account/home.htm
    www.zuobian.com/account/home/xxx --> www.zuobian.com/account/home/xxx.htm
    www.zuobian.com/account/home/xxx.xxx --> www.zuobian.com/account/home/xxx.htm
    www.zuobian.com/manage/ --> www.zuobian.com/manage/login.htm
    www.zuobian.com/manage/company --> www.zuobian.com/manage/company.htm
    www.zuobian.com/manage/company.html --> www.zuobian.com/manage/company.htm
    www.zuobian.com/manage/company.xxx --> www.zuobian.com/manage/company.htm
    www.zuobian.com/manage/company. --> www.zuobian.com/manage/company.htm
    www.zuobian.com/manage/company --> www.zuobian.com/manage/company.htm
    www.zuobian.com/manage/company/ --> www.zuobian.com/manage/company.htm
    因为后端 java 只接收拦截.htm 请求;
    自己写了一个 nginx rewrite 正则:
    rewrite ^/(account|manage)(\/|\.|.[\w]*|[\w]*)$ http://$host/$1/login.htm break;
    rewrite ^/tour/$ http://$host/index.htm break;
    rewrite ^/(account|manage|tour)([\/|\w]*)(\.|\/|.[\w]*|[\w]*)$ /$1$2.htm break;

    感觉不是很飘逸,跪求高手发一个比较好的配置,谢谢
    6 条回复    2015-03-06 17:01:52 +08:00
    zxc337
        1
    zxc337  
    OP
       2014-08-25 15:44:30 +08:00
    没有玩nginx的高手吗?
    msg7086
        2
    msg7086  
       2014-08-26 08:19:46 +08:00
    说句实话,需求太多太乱一般人懒得看……
    seki
        3
    seki  
       2014-08-26 10:15:13 +08:00
    能用就好啦,合并成一条是好看,但是我觉得改天你就不知道这个 rule 是什么意思了,就算你还能读懂,以后接你手的人也会被坑一下的……
    Liang
        4
    Liang  
       2014-08-26 11:50:42 +08:00
    自寻烦恼,何必呢。。。
    zxc337
        5
    zxc337  
    OP
       2014-08-27 11:25:29 +08:00
    客服需求,明白吗?求高手给个解决方案吧,谢谢
    zxc337
        6
    zxc337  
    OP
       2015-03-06 17:01:52 +08:00
    Nginx+Lua+GraphicsMagick实现动态生成指定尺寸的图片,我这个方法可以吗? http://lawrence-zxc.github.io/2014/09/18/blog3/
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1763 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 16:33 · PVG 00:33 · LAX 08:33 · JFK 11:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.