nginx rewrite does not work without "permanent" directive

Francis Daly francis at daoine.org
Fri Dec 15 13:18:00 UTC 2017


On Fri, Dec 15, 2017 at 03:48:20PM +0300, Alexander Trofimchouk wrote:

Hi there,

> My nginx rewrite works only if I add "permanent" directive. Without it there
> is no rewrite seen even in browser's network log.

http://nginx.org/r/rewrite

"rewrite" does not directly lead to "http redirect" without specific
configuration.

> For example: User requests http://site.com/files/imagecache/thumb/1.jpg,
> Nginx tries to find the file or redirects to
> http://site.com/www2/web/app_dev.php/image/cache?path=thumb/1.jpg

No, that's not what your config says.

nginx *rewrites* to /www2/web/app_dev.php/images/cache?path=thumb/1.jpg

That rewritten request (depending on the omitted config) probably is
handled within

  location ~ ^/www2/web/(app_dev|config)\.php(/|$) {

which does the fastcgi_pass to PHP.

If you want nginx to *redirect*, you have to tell it to, using one of
the three documented methods.

> If I add "permanent" I get Symfony controller output in browser - which is
> OK. What did I do wrong?

You left off "permanent" or "redirect" or didn't start the replacement
string with "http://", if you wanted nginx to issue a redirect.

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list