Rewrite URL to only show value of $_GET argument

Andrew Martin andrew.s.martin at gmail.com
Mon Sep 9 12:51:59 UTC 2013


Thanks for the suggestions. I was not able to get $arg_title to work. Here
is the relevant section of my nginx config:
        server_name mysite.com;

        try_files $uri $uri/ index.php;

        location / {
                 rewrite ^/index\.php?title=(.*)$
http://mysite.com/$arg_title redirect;
        }

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;

                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi_params;
        }

I also tried the rewrite rule inside of the "location ~ \.php$" block, but
it didn't work there either. Visiting
mysite.com/index.php?title=my_test_page just loads that URL, it does not
redirect to mysite.com/my_test_page. Moreover, visiting
mysite.com/my_test_page results in a 404. What else should I try to make
this rewrite rule work?

Thanks,

Andrew


On Mon, Sep 9, 2013 at 3:57 AM, edogawaconan <me at myconan.net> wrote:

> On Mon, Sep 9, 2013 at 3:58 PM, mex <nginx-forum at nginx.us> wrote:
> >> rewrite ^/index\.php?title=(.*)$ http://www.mysite.com/$1 redirect;
> >
> > this doesnt work? what is $1 then in the redirected request?
> >
>
> of course this won't work. Query string isn't part of rewrite matching
> string.
>
> Use $arg_title instead.
>
> http://nginx.org/en/docs/http/ngx_http_core_module.html#variables
>
> --
> O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20130909/ed86476d/attachment.html>


More information about the nginx mailing list