Welcome! Log In Create A New Profile

Advanced

Redirect user base on Referer

Posted by maitrungduc1410 
Redirect user base on Referer
March 09, 2019 01:14PM
Hi guys,
Currently I'm having a problem.

I have 2 domains: example1.com, example2.com

In domain example1.com I have an HTML file with a small javasscript code: location.replace(location.href.split("#")[0]); (this means page will be reload when user access the page)

In my Nginx config file, at location / , I check if there's Referer field in request header ($http_referer) with value contain Example1.com, I will redirect them to example2.com
using write: rewrite ^ http://example2.com permanent; else I just keep serving the HTML in Example1.com

But the problem is, when I up the server, access example1.com, the page keep refreshing many many times until then browser is stop.

When I try change replace the Javascript code to: <a href="/">Redirect Link</a> (this means when user click, the page at example1.com will be refresh)

In this case everything is fine, after click the link user is redirected to example2.com, it means the referer has value match my condition set above.

I tried same thing with Cookie, but got same problem

What I'm wondering is, it seems like at the time user enter page, Nginx server see nothing in header and then keep serving the HTML of Example1.com so it leads to page reload again and again. It seems everything is empty at the very first time when user access page.

Does anyone know this issue can help me?

Thank you so much
Attachments:
open | download - Screen Shot 2019-03-10 at 02.10.08.png (28.9 KB)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 308
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready