Score:0

Rerouting requests from site.org/old to site.org/new in nginx

cn flag

I have a site deployed at www.site.org. I have routes at www.site.org/old/article and I want to automatically redirect people to www.site.org/new/article. Ideally this would work as a wildcard to capture anything and not just article.

I'm not great at Nginx so any advice would be useful on best practices. I have seen a few people do it with location blocks with a mixture of return 301 woven in as well as straight up rewrites.

Score:0
gr flag

Assuming you want an HTTP 301 permanent redirect rather than serving the old URL like it is a new one, use

rewrite ^/old(/.*) /new$1 permanent;

If I am wrong and you want to serve both /old/article and /new/article the same way without a redirection, use the same rewrite rule without the permanent flag (should be placed at the server context, not the location one!):

rewrite ^/old(/.*) /new$1;
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.