Rewrite URL to only show value of $_GET argument

Andrew Martin andrew.s.martin at
Wed Sep 11 13:32:09 UTC 2013


Using the similar statement "try_files $uri $uri/ /index.php;", if I visit
this URL:
then the URL is rewritten to this, but it just loads the contents of
index.php (without the title variable):
What it shows would be equivalent to going to this page:

The part of my nginx configuration which communicates with php is:
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_index index.php;
                include fastcgi_params;

The php code is a custom page, not a pre-built CMS. It is doing an ajax
call to load the content, but should be functionally-equivalent to this:
<!-- header code here -->
if (isset($_GET['title'])) {
     include($_GET['title'] . ".html");
} else {
<!-- footer code here -->

If I go to this page:
I would like the client's browser to instead show this URL:

Does this help clarify what I am looking for?



On Wed, Sep 11, 2013 at 7:43 AM, Francis Daly <francis at> wrote:

> On Tue, Sep 10, 2013 at 09:07:46PM -0500, Andrew Martin wrote:
> Hi there,
> > Would it be possible to only redirect if the title $_GET variable is
> > present?
> Yes.
> Use something like
>   if ($arg_title != "") {
>     return 302$arg_title;
>   }
> inside the "location = /index.php" block, and then continue with whatever
> should happen if $arg_title is empty.
> > Thanks for clarifying this. The complete behavior I'm looking for is
> just to
> > create SEF URLs for pages on the site by hiding the index.php?title= part
> > of the URL. Thus, visiting /my_test_page in your browser would internally
> > load the index.php?title=my_test_page URL but display the SEF URL to
> > the user. How can I achieve this behavior?
> I suspect that "try_files $uri /$uri /index.php;" might be enough for
> what you ask for here; if it isn't, then a description of what you do,
> what you see, and what you expect to see, will probably make it easier
> to understand where the problem is. (Your fastcgi-related configuration,
> and the php code itself, will determine whether it is enough.)
> If you search for nginx + your-php-application, do you see any
> documentation on how to create SEF URLs? It may be easier than me
> guessing here.
>         f
> --
> Francis Daly        francis at
> _______________________________________________
> nginx mailing list
> nginx at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list