Redirect by visitor’s IP address

http://c {
root /var/www
# First redirect
rewrite {
if {remote} starts_with 192.168.1.
to /long-url-1
redir /long-url-1 https://extremely-long-url/1
# Second redirect
rewrite {
if {remote} starts_with 192.168.2.
to /long-url-2
redir /long-url-2 https://extremely-long-url/2

I found the above code in forum. The code worked.
But my website is on Cloudflare and I installed realip plugin now.
how do I change {remote} to realip? many thanks again.

With realip, you continue to use {remote}.

The plugin simply corrects {remote} (or more specifically the variable that placeholder reads from) to the actual end-user’s IP address, as advised by an intermediate proxy such as via the X-Forwarded-For header.

Check the examples in the documentation for realip usage:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.