Help with redirect from old to new URL

Francis Daly francis at
Sun Sep 9 14:36:24 UTC 2012

On Sun, Sep 09, 2012 at 09:54:56AM -0400, kfawcett wrote:

Hi there,

> The only difference in the URLs is a switch from underscores to hyphens, and
> from /idx/ to /property/. 
> Here is the old URL:
> Here's the new URL:
> Any ideas how to redirect all of these URLs without knowing what every one
> of the 40,000+ URLs are?

Within "location /idx/", dynamically generate the new url, and issue a
redirect to that. "dynamically" means "use one of the embedded languages,
or else talk to an external server".

An incomplete example using fastcgi and php is:

file /tmp/idx-fixup:
$new = str_replace('_', '-', $old);
$new = substr_replace($new, '/property', 0, 4);

header("Status: 301 Moved Permanently");
header("Location: $new");

fragment of nginx.conf:
        location /idx/ {
            include fastcgi.conf;
            fastcgi_pass  unix:php.sock;
            fastcgi_param  SCRIPT_FILENAME    /tmp/idx-fixup;

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list