Nginx rewrite help: SEO/Permalink
Tobia Conforto
tobia.conforto at gmail.com
Mon Feb 1 17:34:40 MSK 2010
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20100201/632f0da3/attachment-0001.html>
More information about the nginx
mailing list