Understanding alias (used as rewrite)

E.B. emailbuilder88 at yahoo.com
Mon Jun 22 20:32:17 UTC 2015


> > So I was confucsed why this not working:
> >
> > location ^~ /my-long-prefix-goes-here  {
> >   alias /another/different/path/anotherscript.php;
> >   include fastcgi.conf;
> > }
> >
> > In other words, alias of exact location match does
> > a cheap "rewrite" perfectly. But now I want to match
> > addresses like:
> >
> > /my-long-prefix-goes-here
> > /my-long-prefix-goes-herexxx
> > /my-long-prefix-goes-here/
> > /my-long-prefix-goes-here/filename
> >
> > Only the first one works, the others are 404. Is
> > Nginx adding the tail end of the matched prefix
> > to the aliased location? I tried to make my alias:
> >
> > alias /another/different/path/anotehrscript.php?;
> >
> > so the stuff on the end turns into a query arg which
> > php can ignore. But that didn't work.
> >
> > I also tried to use regex to match the location:
> >
> > location ~ ^/my-long-prefix-goes-here  {
> >
> > But now NONE of the addresses work - even the
> > exact match is 404. Why??
> >
> > I found this was the only way to make it work:
> >
> > root /another/different/path;
> > rewrite ^(.*)$ /anotehrscript.php break;
> >
> > In this situation is rewrite the only solution?
> 
> >
>
> You're probably looking for this
> 
> fastcgi_param SCRIPT_FILENAME /another/different/path/anotehrscript.php;

Excellent point! Thanks you!
However, what if the alias was NOT to a php file? Is using
rewrite the only solution - alias not able to working? What
is alias doing to cause 404?



More information about the nginx mailing list