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

2019-08-05 22:02:36 +08:00
 alanying

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

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

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

1888 次点击
所在节点    问与答
20 条回复
alanying
2019-08-05 23:06:44 +08:00
顶起求看到
Humorce
2019-08-05 23:32:19 +08:00
Rewrite
registerrr
2019-08-05 23:35:40 +08:00
直接 onload (){window.open(window.location.href + “?aff=001 “)}
luofeii
2019-08-05 23:45:34 +08:00
后端 setHeader("Location",跳转地址拼接参数),状态码 307
alanying
2019-08-06 00:16:29 +08:00
@Humorce 就是不太想的好 Rewrite 该怎么写
alanying
2019-08-06 00:16:53 +08:00
@registerrr 在 nginx 那边加这个么?
limuyan44
2019-08-06 01:37:32 +08:00
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
2019-08-06 01:57:06 +08:00
@limuyan44 这种情况用 return 301 不行吗?一定要用 rewrite 吗?
ysc3839
2019-08-06 02:03:40 +08:00
@limuyan44
Nginx 官方文章 Pitfalls and Common Mistakes 恰好就写了这种错误
https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#taxing-rewrites

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

return 301 http://www.zycat.top$uri?aff=001;
}
alanying
2019-08-06 13:03:47 +08:00
limuyan44
2019-08-06 13:18:38 +08:00
@alanying 你这种需求不需要写正则了
location / {
return 301 http://www.zycat.top$uri?aff=001;
}
alanying
2019-08-06 13:23:51 +08:00
@limuyan44 我自己写了个

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

```

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/589328

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX