简体   繁体   中英

Nginx Rewrite URL replacement for Apache rewrite

如何为以下内容转换nginx等效URL重写:

RewriteRule ^read/([0-9]+)/?$ /read/?u=$1 [QSA,L]

Give the following a try:

rewrite ^read/([0-9]+)/$ /read/?u=$1 permanent;

IfIsEvil - hence direct rewrite option.

You can do this in two ways, with a location:

# the ?<u> assigns the capture to $u.  Some older pcres need ?P<u>
location ^/read/(?<u>[0-9]+)/?$ {
  rewrite ^ /read/?u=$u last;
}

or with just a rewrite:

rewrite ^/read/([0-9]+)/?$ /read/?u=$1 last;

nginx will append the query string by default (you can disable the behavior by adding another ? at the end of the rewrite target).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM