【问题标题】:URL redirection to a non-http url, in nginx在 nginx 中 URL 重定向到非 http url
【发布时间】:2016-06-01 16:14:25
【问题描述】:

我使用 nginx 作为反向代理。如何在 nginx 的 server 块中设置 URL 重定向,使得重定向到的 URL 是 non-http url

例如,我有一个类型的 url:

http://example.com/user_uuid/a0d525aa-d755-11e5-b5d2-0a1d41d68578/14084561234/

我想从上面重定向到非http url:

sms:14084561234?body:my photo is located at http://example.com/photos/a0d525aa-d755-11e5-b5d2-0a1d41d68578/

当这个非 http url 访问浏览器时,设备的原生 SMS 应用程序会打开,并在 SMS 中预先填写电话号码 1-408-456-1234 和正文中出现在 ?body 之后的文本非 http 网址。当然,这仅适用于移动设备。

这样的事情可能吗?如果是这样,你能给我举个例子吗?请注意,在第一个 URL 中,uuid 和数字是根据一些先前的输入动态生成的。


我已经知道如何在我的 Web 应用程序代码中实现重定向,但这不是问题所在。

【问题讨论】:

    标签: redirect nginx url-redirection http-redirect


    【解决方案1】:

    以下配置有效:

    server {
        listen 99;
        server_name test.so;
    
        location /user_uuid {
            rewrite /user_uuid/(.+)/([^/]+) "sms:$2?body:my photo is located at http://example.com/$1/" redirect;
        }
    
    }
    

    样本输出

    curl -I -H "Host: test.so" http://localhost:99/user_uuid/uuid/phone/
    
    HTTP/1.1 302 Moved Temporarily
    Server: nginx/1.7.11
    Date: Sat, 20 Feb 2016 00:45:22 GMT
    Content-Type: text/html
    Content-Length: 185
    Connection: keep-alive
    Location: sms:phone?body:my photo is located at http://example.com/uuid/
    

    【讨论】:

    • 感谢您的回复。我会对其进行测试并回复您。
    猜你喜欢
    • 2013-01-11
    • 1970-01-01
    • 2021-04-16
    • 2016-08-09
    • 2019-09-27
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 2013-06-11
    相关资源
    最近更新 更多