Nginx的rewrite简单测试(存档)

下午做了一下nginx的简单rewrite测试,原来在kds.1vs1.cn上对apache做了rewrite,在转移到nginx之后,原有的rewrite规则不变,匹配规则写法变化不大。

在httpd.conf中的写法:

RewriteEngine On
RewriteRule /index_([^/]*).html /templete1/index\.php\?itemID=$1 [L]
RewriteRule /doc_([^/]*).html /goDoc\.php\?docID=$1 [L]

在nginx.conf中的写法:

rewrite "/index_([^/]*).html" /templete1/index.php?itemID=$1 last;
rewrite "/doc_([^/]*).html" /goDoc.php?docID=$1 last;
rewrite "/aboutMe" /aboutMe.php last;
rewrite "userReg" /userReg.php last;

效果:

http://kds.1vs1.cn/index_5.html  =>  http://kds.1vs1.cn/templete1/index.php?itemID=5
http://kds.1vs1.cn/doc_355.html  =>  http://kds.1vs1.cn/goDoc.php?docID=355

发表评论