V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
daijinming
V2EX  ›  程序员

URL 重写 正则表达式求教

  •  
  •   daijinming · 2019-03-18 11:30:04 +08:00 · 1666 次点击
    这是一个创建于 1860 天前的主题,其中的信息可能已经有所发展或是发生改变。

    原始地址:demo.com/_/app1/index.html ,重写后客户端看到的网址:demo.com/_app1/index.html, 如果要达到这样的重写效果,不知道正则表达式怎么写

    4 条回复    2019-03-18 18:57:47 +08:00
    coolloves
        1
    coolloves  
       2019-03-18 13:49:30 +08:00
    rewrite ^/([^/]+)/([^/]+)/(.*) /$1$2/$3 break;
    daijinming
        2
    daijinming  
    OP
       2019-03-18 15:18:16 +08:00
    @coolloves 感谢,但是这个好像对静态资源不管用,估计只对控制器有作用
    imlinhanchao
        3
    imlinhanchao  
       2019-03-18 17:00:42 +08:00   ❤️ 1
    @daijinming 静态资源可以在 Nginx 做
    TomVista
        4
    TomVista  
       2019-03-18 18:57:47 +08:00   ❤️ 1
    global.asax
    protected void Application_BeginRequest(object sender, EventArgs e)
    {
    if (Context.Request.FilePath == "/") Context.Request.rewrite(" something")
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2590 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 04:27 · PVG 12:27 · LAX 21:27 · JFK 00:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.