假设您有一个urlwww.answers.mydomain.com/category/hello_world-123.html,但是您想要将path部分改写为/ category / hello-world
如何用nginx重写呢? 基本上我怎样才能格式化$ 1variables?
server{ listen 80; server_name ~^(?<subdomain>.+)\.bg\.com$ root /home/dan/Projects/rewrite-example; set $PREFERRED_DOMAIN $scheme://www.bg.com; if ($subdomain ~* answers) { rewrite ^(.*)$ $PREFERRED_DOMAIN/questions$1 permanent; } }
server{ listen 80; server_name answers.bg.com; rewrite ^(.+/[az]+)-\d+\.html$ http://www.bg.com$1 permanent; rewrite ^(.+/[az]+)_([az]+)-\d+\.html$ http://www.bg.com$1-$2 permanent; rewrite ^(.+/[az]+)_([az]+)_([az]+)-\d+\.html$ http://www.bg.com$1-$2-$3 permanent; rewrite ^(.+/[az]+)_([az]+)_([az]+)_([az]+)-\d+\.html$ http://www.bg.com$1-$2-$3-$4 permanent; rewrite ^(.+/[az]+)_([az]+)_([az]+)_([az]+)_([az]+)-\d+\.html$ http://www.bg.com$1-$2-$3-$4-$5 permanent; }