Nginx rewrite help: SEO/Permalink
Harish Sundararaj
tuxtoti at gmail.com
Thu Feb 4 11:20:55 MSK 2010
Tobia,
Thank a ton. This is interesting. I got to know that I'll anytime have only
4 Filters. So it eases my work. I can probably create 4 different location
blocks
Anyways, thanks once again.
-
Harish
On Mon, Feb 1, 2010 at 8:04 PM, Tobia Conforto <tobia.conforto at gmail.com>wrote:
> Harish Sundararaj wrote:
>
> I have a list which is something like this:
> keyA : a1,a2
> keyB : b1,b2
> keyC : c1, c2
> the access URL will be http://example.com/results/myquery/keyB-keyD-keyK
> This should translate to /results?q=myquery&keyvals=b1,b2,d1,d2,k1,k2
>
>
> Here is one way to do it inside nginx. It's sub-optimal, as it sends
> several redirects back to the user (one for each key) but it's a start.
>
> You are probably better off using something like the Perl module anyways.
>
> # map of key/value pairs
> map $key $val {
> keyA a1,a2;
> keyB b1,b2;
> keyC c1,c2;
> }
>
> # redirect for one key
> location ~ ^/results/([^/]+)/([^-]+)$ {
> set $query $1;
> set $key $2;
> if ($arg_keyvals) { set $sep ","; }
> rewrite ^ /results?q=$query&keyvals=$arg_keyvals$sep$val? permanent;
> }
>
> # intermediate redirect for more than one key
> location ~ ^/results/([^/]+)/([^-]+)-(.+)$ {
> set $query $1;
> set $keys $3;
> set $key $2;
> if ($arg_keyvals) { set $sep ","; }
> rewrite ^ /results/$query/$keys?keyvals=$arg_keyvals$sep$val? permanent;
> }
>
>
> Tobia
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20100204/94ea744d/attachment.html>
More information about the nginx
mailing list