Welcome! Log In Create A New Profile

Advanced

Re: Best practice for URL rewriting with php parameter

November 11, 2015 01:56PM
Hello Francis,
First thank you for your answers

I tried both methods but none of them worked. I'm going to look at it more in details (and display the php logs because I just had a blank page).
Also I would like to know why the solution you're offering is a "best practice" ?At first it seems a bit heavy because I'll have a paragraph like that for every x variable (x=information, x=something). Considering also that the users URL might not look like the x variable.nginx.org/info_1234 is an internal rewrite of index.php?x=information
I tried two other solutions that workedrewrite /info_1234 /index.php?x=information;
and
location = /info_1234 { try_files info_1234 /index.php?x=information; }
I would like to understand why your solution is better than these, why is it a best practice ?
Thank you




Le Mercredi 11 novembre 2015 16h47, Francis Daly <francis@daoine.org> a écrit :



On Wed, Nov 11, 2015 at 02:29:37PM +0000, Mik J wrote:

Hi there,

> > I want that a user who accessesnginx.org/informationwill be redirected in the background tonginx/index.php?x=informationSo that my index.php page is dymanic
>
> What does "redirected in the background" mean?M => I just meant that the user won't see the php parameters. He just sees a simple url with text only.Nginx passes the parameter to php, and not the user (through GET). That's what I meant by "in the background"

That's clear, thanks. In nginx terms, it's an internal rewrite.

> > I did like this in my virtual host configurationlocation /information { try_files information /index.php?x=information; }
> > I would like to know if:a) This is the best practice to do what I would like to do ?
>
> I'd say "no".
>
> I'm not fully sure what it is that you want to do, but I suspect that
> "rewrite" (http://nginx.org/r/rewrite) may be what you want; unless
> you will describe how /index.php is intended to be handled -- in which
> case just using (e.g.) fastcgi_pass with some suitable fastcgi_param
> directives might be even better.
> M => My index.php looks like this<?php
> if ($_GET['x']) == 'information') { echo "This is the information Page"; }
> if ($_GET['x']) == 'contact') { echo "This is the contact Page"; }
> ?>

Your nginx will have some way to cause your index.php to be
processed. Maybe it is proxy_pass to a php-enabled web server; maybe it
is fastcgi_pass to a fastcgi server, maybe it is something else.

If you do something like

  location = /information { rewrite ^ /index.php?x=information; }
  location = /index.php {
    fastcgi_pass ...;
    fastcgi_param SCRIPT_FILENAME $document_root$uri;
    fastcgi_param QUERY_STRING $query_string;
  }

then you could instead omit the rewrite, and just do something like

  location = /information {
    fastcgi_pass ...;
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    fastcgi_param QUERY_STRING x=information;
  }

directly.

    f
--
Francis Daly        francis@daoine.org

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx



_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Best practice for URL rewriting with php parameter

miky November 11, 2015 08:16AM

Re: Best practice for URL rewriting with php parameter

Francis Daly November 11, 2015 08:56AM

Re: Best practice for URL rewriting with php parameter

miky November 11, 2015 09:32AM

Re: Best practice for URL rewriting with php parameter

Francis Daly November 11, 2015 10:48AM

Re: Best practice for URL rewriting with php parameter

miky November 11, 2015 01:56PM

Re: Best practice for URL rewriting with php parameter

Francis Daly November 11, 2015 02:40PM

Re: Best practice for URL rewriting with php parameter

miky November 12, 2015 06:06PM

Re: Best practice for URL rewriting with php parameter

Francis Daly November 15, 2015 07:28AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 222
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