What I want to do:
- Check if the request comes from Facebook.
- Check if the URL matches domain.com/2
- If the above conditions are met - show contents from / api / content / item / $ 1? social = 1
- If the above conditions are false - show a "normal page"
This is a one page application. Before my change configuration looked like this (and it worked):
location / { root /home/eshlox/projects/XXX/project/project/assets/dist; try_files $uri $uri/ /index.html =404; }
I tried using if statements:
location / { set $social 1; if ($http_user_agent ~* "facebookexternalhit") { set $social UA; } if ($uri ~* "^/(\d+)$") { set $social "${social}URL"; } if ($social = UAURL) { rewrite ^/(\d+)$ /api/content/item/$1?social=1; } root /home/eshlox/projects/XXX/project/project/assets/dist; try_files $uri $uri/ /index.html =404; }
In this configuration, everything works as I expected, only if both conditions are true or false. If one of the conditions is true, and the second is false (or vice versa), then nginx always returns 404 status.
I found "IfIsEvil" on the nginx website, I tried to use the mapping (can I use the mapping in this case?), But still I can not solve this problem.
Any ideas?
Sincerely.
nginx
eshlox
source share