A little bit of nginx

Took me a moment to find out how to redirect a URL if the URL contains a certain word, in Nginx, here it is:

location ~ \.xml$ {
rewrite ^(.*)$ http://urltoberedirected.com/$1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://urltoberedirected.com/$1;
}

This one is going to redirect each URL which ends with .xml to urltoberedirected.com

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.