nginx: How do I redirect all requests to the frontpage?

I am shutting down a website and am stumped on a really simple problem; I need to redirect all URLs to the homepage (except, obviously, the homepage itself).

I thought this should work, but it causes the homepage to get in a loop.

rewrite ^/.+ $scheme://$server_name permanent;

I thought that would have meant any URL containing 1 or more characters. (Homepage obviously containing none).


Found an answer on StackOverflow - clearly hadn't used the right combination of keywords before.

https://stackoverflow.com/a/22465987/224707

Basically:

location / {
    rewrite ^ http://example.com;
}
location = / {
}