Updating a 301 permanent redirect

If you change the URL for a 301 redirect (at least a redirect powered by NGINX), the browser does not respect the new URL. This appears to be because the browser caches the URLs for 301 redirects, because they are supposed to be permanent.

If you google online, everyone tells you “you’re screwed”. You have to clear the browser’s cache or do some sort of three-way redirect.

However, a buddy and I found a work-around (in NGINX). All you have to do is change it from 301 to 307, and the browser re-checks the URL that it should redirect to, like so:

server {
       expires 1m;
       server_name my.host.name;

       return 307 http://my.com/updated/redirect/here;
}

We have also added an expiration of 1 minute just to make sure the browser doesn’t hold onto the URL anyways.

Leave a Reply

Your email address will not be published.

Humanity Verification *Captcha loading...