How to set Nginx URI to fix empty URI in redirect to named location
<p>The problem: when accessing our website with an invalid URL that contains a '%' sign, Nginx throws a 400 Bad Request error.</p>

<p>Instead of the Nginx page, we would like to rewrite the request to a (WordPress) 404 page.</p>

<p>I have tried the following:</p>

<pre><code>location @400 {
    rewrite ^ /404 break;
}

error_page 400 =307 @400;
</code></pre>

<p>However, this generates a 500 Internal Server Error on Nginx.</p>

<p>Nginx error log says: '... empty URI in redirect to named location "@400" while reading client request line..., request: "GET &lt;invalid-url&gt;"'.</p>

<p>This is not unexpected, as the original URL is invalid.</p>

<p>So I guess what I am looking for is to set the URI explicitly for the rewrite. How to do this? Or is there a better approach? I am not that familiar with Nginx.</p>