Rewrite URL to only show value of $_GET argument

Andrew Martin andrew.s.martin at gmail.com
Fri Sep 20 04:33:28 UTC 2013


Steve,

Thanks for the suggestion. How would this additional check change the
solution I proposed on 9/16? It looks like it would prevent the rewrite
from occurring if other arguments (instead of title) were present?

Thanks again,

Andrew


On Sun, Sep 8, 2013 at 11:31 PM, Steve Holdoway <steve at greengecko.co.nz>wrote:

> I think you need to do some regexp on the args
>
> if ( $args ~ title=([^&]+) {
>         rewrite ^(.*)title=([^&]+).*$ /article/$2? last;
> }
>
> Note... totally untested.
>
> Steve
>
>
> On Sun, 2013-09-08 at 23:01 -0500, Andrew Martin wrote:
> > Hello,
> >
> >
> > I have read through the nginx rewrite documentation and looked at
> > various examples, but can't figure out how to create a rewrite rule
> > for the following (if it is possible). I'd like to rewrite the URL of
> > a php file with a $_GET argument and replace it with just the value of
> > the $_GET argument. For example, I'd like to
> > replace /index.php?title=my_example_title with /my_example_title
> > or /article/my_example_title. I've tried several regular expressions
> > to match index.php, as well as the $args and $arg_title nginx
> > variables, but cannot get this working. For example:
> > rewrite ^/index\.php?title=(.*)$ http://www.mysite.com/$1 redirect;
> >
> >
> >
> > Can anyone provide inside into how to correctly rewrite this type of
> > URL?
> >
> >
> > Thanks,
> >
> >
> > Andrew
> > _______________________________________________
> > nginx mailing list
> > nginx at nginx.org
> > http://mailman.nginx.org/mailman/listinfo/nginx
>
> --
> Steve Holdoway BSc(Hons) MIITP
> http://www.greengecko.co.nz
> Linkedin: http://www.linkedin.com/in/steveholdoway
> Skype: sholdowa
>
> _______________________________________________
> 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/20130919/22bfd476/attachment.html>


More information about the nginx mailing list