NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
coagent
V2EX  ›  NGINX

Nginx 重写规则请教

  •  
  •   coagent · Nov 16, 2016 · 3382 views
    This topic created in 3486 days ago, the information mentioned may be changed or developed.
    如何用 rewrite 重写网址:
    https://weixin.domain.com/m/#!/sethelp/setindex

    到:

    https://www.domain.com/sethelp/setindex

    试了 N 遍和 N 种方法,那个 #!字符匹配老是有问题。

    1. rewrite /m/#!/(.*)$ https://www.domain.com/$1 break;
    2. rewrite /m/([#!]+)/(.*)$ https://www.domain.com/$2 break;

    3.

    location ^~/m/ {
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Forwarded-Port $server_port;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host www.domain.com;
    proxy_redirect off;
    rewrite /m/([#!]+)/(.*)$ /$1 break;
    proxy_pass https://www.domain.com/;
    }


    请大神帮忙看如何解决?
    3 replies    2016-11-16 00:35:08 +08:00
    XiaoxiaoPu
        1
    XiaoxiaoPu  
       Nov 16, 2016   ❤️ 1
    http://www.ruanyifeng.com/blog/2011/03/url_hash.html

    服务器收到的请求不包含 "#" 及后面的部分。
    lhbc
        2
    lhbc  
       Nov 16, 2016 via iPhone   ❤️ 1
    #后面的是交给浏览器和 js 处理的,浏览器请求并不会发送#后面的内容

    看你这规则,你应该用 js 来处理
    coagent
        3
    coagent  
    OP
       Nov 16, 2016
    @lhbc @XiaoxiaoPu 秒懂了,谢谢!刚才配置时搞晕了...
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   972 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 21:44 · PVG 05:44 · LAX 14:44 · JFK 17:44
    ♥ Do have faith in what you're doing.