apache rewrite 如何转成 nginx rewrite

浏览:37日期:2022-08-01

问题描述

I am a newbie. 想知道对于 apache rewrite,一般都如何转成 nginx 的,比如下面的 apache 规则怎么转:

<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} !dispatch.php$ RewriteCond %{REQUEST_FILENAME} !-f RewriteRule .* dispatch.php [L,QSA] </IfModule>

问题解答

回答1:

很简单。理解你的 Apache httpd 规则,然后把它的功能用 nginx 的规则写出来。和翻译差不多的事情。

你这个规则是说,如果访问的 URI 不是以 dispatch.php 结束的,并且访问的文件不存在,那么就重定向到 dispatch.php 上。nginx 里可以直接这么写:

try_files $uri /dispatch.php;回答2:

Apache Rewrite转Nginx Rewrite

相关文章: