410 and redirect setups for NGINX


(Douglas (@finnatic at @waikato)) #1

With Apache we’ve sometimes made use of the 410 GONE http status code to indicate that resources have gone away to crawlers etc alongside an html page for human visitors.

E.g. something like:

    ErrorDocument 410 ourmovedpage
    ...
    Redirect gone /GONECONTENT

Has anyone come up with something similar for Nginx? I’ve crossposted this to stackoverflow, but are just curious if any Matrix users might have something that we could use?


(Marcus Fong) #2

What’s the problem you’re having, exactly? I just tried this in an Nginx virtualhost and it worked fine:

    location /410test {
            return 410;
    }
    error_page 410 /error-page;

When I go to /410test it gives me a 410 Gone status with the contents of /error-page.


(Douglas (@finnatic at @waikato)) #3

I was trying:

location = /gonecontent-address {
   error_page 404 =410 $scheme://ourdomain/ourmovedpage.html?ref=gonecontent-address;
}

an answer on stackoverflow suggests having a FQDN before the error page may trigger a redirect, so I’ll look into what I can do to host the movedpage content on the squiz system in question.


(Douglas (@finnatic at @waikato)) #4

End solution:

location = /gonecontent-address { error_page 404 =410 /page-moved?gonecontent-reference; }

alongside a standard Matrix page with numerous sections which output customisable content per gonecontent-reference e.g.:

%begin_globals_server_query_string^eq:gonecontent-reference%

%end_globals%