redirect - nginx rewrite rule to remove - and _ -
i need nginx rewrite rule next problem:
i have urls include several hyphen , underscores
example request: http://www.example.com/cat/cat2/200-ab---a-12_12-123.312/cat-_-cat/cat/dog---i
would give 404 error in need 301- redirect to:
http://www.example.com/cat/cat2/200-ab-a-12-12-123.312/cat-cat/cat/dog-i
so underscores should replaced hyphens , there should 1 hyphen time.
short version: replace --- - , replace _ - replacing _ - -_- become --- , rule 1 have called again.
is possible to in 1 rule? , if not how other way :)i have absolutely no thought how nginx
any help appreciated :)
% nginx -c $pwd/test.conf % curl -i localhost:8080/cat/cat2/200-ab---a-12_12-123.312/cat-_-cat/cat/dog---i http/1.1 301 moved permanently server: nginx/1.3.13 date: wed, 20 feb 2013 00:09:50 gmt content-type: text/html content-length: 185 location: http://localhost:8080/cat/cat2/200-ab-a-1212-123.312/cat-cat/cat/dog-i connection: keep-alive % cat test.conf events { } #error_log logs/error.log debug; http { server { hear 8080; location /cat/cat2/ { # replace 3 inconsecutive # uderscores per internal redirect rewrite "^(.+?)_+(?:(.+?)_+)?(?:(.+?)_+)?(.+)$" $1$2$3$4 last; # replace 3 inconsecutive multiple # hyphens per internal redirect rewrite "^(.+?-)-+(?:(.+?-)-+)?(?:(.+?-)-+)?(.+)$" $1$2$3$4 last; homecoming 301 $uri; } } }
redirect url-rewriting nginx rewrite
No comments:
Post a Comment