Welcome! Log In Create A New Profile

Advanced

Re: A pretty URL for a specific PHP page?

Francis Daly
September 10, 2021 05:32PM
On Mon, Sep 06, 2021 at 02:58:37PM +1000, Jore wrote:

Hi there,

> Is it possible to make a pretty URL for a specific PHP page?

Some php scripts make it straightforward, by handling that themselves. I
guess that yours is not one of those?

> I'd like https://domain.com/report/ to render
> https://domain.com/index.php?r=app%2Fform&id=2lyEsw

The simple thing -- that you possibly do not want to do here? -- would be
to redirect to the desired url; in that case, the browser would make the
"pretty" request, get the redirect response, make the "real" request,
and get the full response. That would be something like

location = /report/ { return 301 /index.php?r=app%2Fform&id=2lyEsw; }

> So I tried this location block, but I get 403 forbidden:
>
>     location /report {
>         index index.php?r=app%2Fform&id=2lyEsw;
>         alias /var/www/easyforms;
>     }

"index" expects a filename argument; when that fails, it will probably
try a directory index of /var/www/easyforms, which presumably leads to
the 403 here.

What you can try, is to call fastcgi_pass with appropriate parameters,
directly.

The exact parameters wanted by your fastcgi server and by your php script,
depend on what they expect. And if you send the same parameter name more
than once, whether the fastcgi server will provide the first, the last,
or all amalgamated, to the php script, depends on the fastcgi server.

But often "SCRIPT_FILENAME" and "QUERY_STRING" are enough to start with;
if you need other things from your fastcgi.conf or fastcgi_params files,
you can "include" those too, in a place where the manually-provided
variables are not overridden.

So the following might have a chance of working as you want; and if
it does not, then the fastcgi error log or the nginx (debug) error log
might help point at other changes that might be needed.

location = /report/ {
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param QUERY_STRING r=app%2Fform&id=2lyEsw;
}

One extra note: if the returned content includes relative links --
something like "img src=new.png"-- then the browser will make a different
follow-up request for it if the browser asked for "/report/", and if
the browser asked for "/index.php?anything". If your output shows some
broken-image links or the like, that might be a thing to check for. But
that only matters after the rest of the config is working.

Good luck with it!

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

A pretty URL for a specific PHP page?

Jore September 06, 2021 01:00AM

Re: A pretty URL for a specific PHP page?

Francis Daly September 10, 2021 05:32PM

Re: A pretty URL for a specific PHP page?

Jore September 11, 2021 07:52AM

Re: A pretty URL for a specific PHP page?

Александр Кириллов September 12, 2021 04:00AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 251
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready