谈谈apache的htaccess伪静态法则转到nginx

上文讲了htaccess转iis的httpd.ini伪静态法则

下面再谈谈如何把apachehtaccess法则转到nginx下!

简朴举个例子,如apache下的这样一条伪静态法则

RewriteRule ^/([0-9]+)/?$ index.php?s=content/index/loupan&t=zhuye&catid=14&id=$1 [L] RewriteRule ^/index.html?$ index.php?s=content/index/loupan&t=zhuye&catid=14&id=$1 [L]转换到nginx下后为下面这样,其实窜改照旧很小的!
location / { rewrite ^/([0-9]+)/?$ /index.php?s=content/index/loupan&t=zhuye&catid=14&id=$1 last; rewrite ^/index\.html$ /index.php?s=content/index/loupan&t=zhuye&catid=14&id=$1 last; }
可是apache下的RewriteCond写法,在nginx下是不认的,这个窜改较量大! RewriteCond %{QUERY_STRING} keyword=(.*) RewriteRule ^/list.html(.*) index.php?s=content/index/lists&catid=14&keyword=%1 [L] if ($query_string ~ ^keyword=(.*)$) { set $id_tmp $1; rewrite "^/list.html$" index.php?s=content/index/lists&catid=14&keyword=$id_tmp permanent; }
必然要留意上面if后头是有个空格的!



内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/8368.html