Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Redirect script sample NGINX code. Make sure this location line sits above the "location /" code in your NGINX config.
location /redirect/ {
rewrite ^/redirect/(.*)$ /redirect/index.php?id=$1 last;
}
@vDevices

This comment has been minimized.

Copy link

commented Aug 20, 2013

I wasn't able to get this code snippet to work until I changed the references to redirect to out. Until then, I kept getting 404s when I would click on a cloaked affiliate link, to test it out.

Please advise if that was an incorrect, or otherwise improper, workaround.

@anandkumar

This comment has been minimized.

Copy link

commented Nov 16, 2013

@vDevices Yes, We have to change the directory according to we have uploaded the files

@brashrebel

This comment has been minimized.

Copy link

commented Dec 27, 2013

Does anyone have an .htaccess equivalent? How would I do this in Apache?

@prasenjithaty

This comment has been minimized.

Copy link

commented Aug 25, 2014

Hi @jdevalk,

Isn't working for me. example.com/out/index.php?id=yoast works for me, but somehow the pretty url part isn't. What am I doing wrong?

location /out/ { rewrite ^/out/(.*)$ /out/index.php?id=$1 last; }

@prasenjithaty

This comment has been minimized.

Copy link

commented Aug 25, 2014

Got it working. I was adding it inside my http block instead of https block

@sceptic30

This comment has been minimized.

Copy link

commented Dec 12, 2014

For some reason, this doesnt work in a wordpress installation (in a normal site yes), anyone imagining why?
Edit, problem solved:
Dont use index.php as link file but choose other file name.

@KoenV91

This comment has been minimized.

Copy link

commented Apr 14, 2016

Can't really figure out how to get it working on NGINX. Do i need to delete the .htaccess file in the /out/ folder and upload this file and change the /redirect/ to the folder name im using? Or do i change code in the general nginxconfig file in the root of my website?

@philiparthurmoore

This comment has been minimized.

Copy link

commented Jul 17, 2017

@sceptic30 Thanks for the heads up. That did the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.