Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Redirect user base on Referer

$
0
0
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

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>