繁体   English   中英

Nginx简单重写

[英]Nginx Simple rewrite

我想在nginx中创建以下URL

comments.php?id=34

变成

/comments/34
/comments/34/

我正在尝试这个并且有效

rewrite  ^/comments/$id/(.*)$  /comments.php?id=$1?  last;

我的问题是, 如何强制将comment.php?id = x重定向到/ comments / id

rewrite ^/comments.php$ /comments/$arg_id? permanent;

根据文档 ,“重写只能在路径上进行,而不能在参数上进行。”

尝试以下方法:

if ($args ~ id=(.+)){
  rewrite comments\.php /comments/$1 last;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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