Simulate 308 redirect in nginx 1.12

gioele asked:

Redirect with status code 308 (Permanent Redirect) is supported in nginx only since version 1.13.

How can one simulate a 308 redirect using only the facilities offered by nginx 1.12?

My answer:


You can wait for nginx 1.14, which will be out in a couple of months.

You can use nginx 1.13, which is available already.

If you don’t want to do either, you’ll need to provide a 308 outside nginx somehow. For instance, in a trivial PHP script.

location = /oldurl {
    rewrite ^ /308.php?location=$new_uri break;
}

Where 308.php might look like:

<?php
header("HTTP/1.1 308 Permanent Redirect");
header("Status: 308 Permanent Redirect");
header("Location: {$_GET['location']}");

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.