V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
alanying
V2EX  ›  问与答

这样的网址跳转应该如何实现? 送金币

  •  2
     
  •   alanying · 2019 年 8 月 5 日 · 2348 次点击
    这是一个创建于 2371 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我的地址是 :abc.com/help1.html

    我想输入地址后,自动跳转到 edf.com/help1.html?aff=001

    然后自动在后门加上 aff 参数,这样的网址跳转应该如何实现?

    20 条回复    2019-08-06 13:23:51 +08:00
    alanying
        1
    alanying  
    OP
       2019 年 8 月 5 日
    顶起求看到
    rzti483NAJ66l669
        2
    rzti483NAJ66l669  
       2019 年 8 月 5 日   ❤️ 1
    Rewrite
    registerrr
        3
    registerrr  
       2019 年 8 月 5 日 via Android
    直接 onload (){window.open(window.location.href + “?aff=001 “)}
    luofeii
        4
    luofeii  
       2019 年 8 月 5 日
    后端 setHeader("Location",跳转地址拼接参数),状态码 307
    alanying
        5
    alanying  
    OP
       2019 年 8 月 6 日
    @Humorce 就是不太想的好 Rewrite 该怎么写
    alanying
        6
    alanying  
    OP
       2019 年 8 月 6 日
    @registerrr 在 nginx 那边加这个么?
    limuyan44
        7
    limuyan44  
       2019 年 8 月 6 日   ❤️ 1
    server {
    listen 80;
    server_name abc.com;
    access_log logs/host.access.log main;
    if ( $request_uri = "/help1.html" ){
    rewrite ^/(.*)$ http://www.edf.com/$1?aff=001 permanent;
    }
    ysc3839
        8
    ysc3839  
       2019 年 8 月 6 日 via Android
    @limuyan44 这种情况用 return 301 不行吗?一定要用 rewrite 吗?
    ysc3839
        9
    ysc3839  
       2019 年 8 月 6 日 via Android   ❤️ 1
    @limuyan44
    Nginx 官方文章 Pitfalls and Common Mistakes 恰好就写了这种错误
    https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#taxing-rewrites

    可以改成 location block + return 301 的形式。
    limuyan44
        10
    limuyan44  
       2019 年 8 月 6 日
    @ysc3839 都可以
    limuyan44
        11
    limuyan44  
       2019 年 8 月 6 日   ❤️ 1
    @ysc3839 看了下文章,return 确实要好,
    @alanying lz 用这个吧
    if ( $request_uri = "/help1.html" ){
    return 301 http://www.edf.com/help1.html?aff=001;
    }
    registerrr
        12
    registerrr  
       2019 年 8 月 6 日 via Android
    @alanying 我这个是纯前端的,能在后端实现更好
    opengps
        13
    opengps  
       2019 年 8 月 6 日 via Android   ❤️ 1
    前端后端控制都行,建议用后端的 redirect
    alanying
        14
    alanying  
    OP
       2019 年 8 月 6 日
    @limuyan44 如果要 help1.html 要修改成其他的页面呢?
    limuyan44
        15
    limuyan44  
       2019 年 8 月 6 日 via Android
    不是很明白你说的其他页面什么意思,按你的要求地址都是写死的,你把 help.html 换成其他页面就好了啊。
    alanying
        16
    alanying  
    OP
       2019 年 8 月 6 日
    @limuyan44 也可以用通配符替换页面名称么? ^(( https|http|ftp|rtsp|mms)?:\/\/)[^\s]+
    limuyan44
        17
    limuyan44  
       2019 年 8 月 6 日   ❤️ 1
    @alanying 支持的,但是还是没明白你要干什么。可能你要的是下面这种?转发请求到新地址并且添加参数?你把 location 后面的表达式换掉,www.zycat.top 换成你自己的就可以了。
    location ~* \.(gif|jpg|jpeg)$ {

    return 301 http://www.zycat.top$uri?aff=001;
    }
    alanying
        18
    alanying  
    OP
       2019 年 8 月 6 日
    limuyan44
        19
    limuyan44  
       2019 年 8 月 6 日
    @alanying 你这种需求不需要写正则了
    location / {
    return 301 http://www.zycat.top$uri?aff=001;
    }
    alanying
        20
    alanying  
    OP
       2019 年 8 月 6 日
    @limuyan44 我自己写了个

    ```bash
    if ($host = 'abc.com') {
    rewrite ^/(.*)$ http://def.com/$1?aff=001 permanent;
    }

    ```
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1993 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 15:28 · PVG 23:28 · LAX 07:28 · JFK 10:28
    ♥ Do have faith in what you're doing.