How to redirect single url in nginx?

tokmak picture tokmak · Aug 3, 2013 · Viewed 223.9k times · Source

I'm in the process of reorganizing url structure. I need to setup redirect rules for specific urls - I'm using NGINX.

Basically Something like this:

http://example.com/issue1 --> http://example.com/shop/issues/custom_issue_name1
http://example.com/issue2 --> http://example.com/shop/issues/custom_issue_name2
http://example.com/issue3 --> http://example.com/shop/issues/custom_issue_name3

Thanks!

Answer

Mohammad AbuShady picture Mohammad AbuShady · Aug 4, 2013
location ~ /issue([0-9]+) {
    return 301 http://example.com/shop/issues/custom_isse_name$1;
}