将这些apache重写规则转换为nginx

时间:2011-04-03 15:45:14

标签: apache nginx rewrite

我无法将这些重写规则转换为nginx;

RewriteRule ^$ requesthandlers/controller.php?page=route [QSA,NC,L]
RewriteRule ^route[/]?$ requesthandlers/controller.php?page=route [QSA,NC,L]
RewriteRule ^board[/]?$ requesthandlers/controller.php?page=board [QSA,NC,L]
RewriteRule ^settings[/]?$ requesthandlers/controller.php?page=settings [QSA,NC,L]
RewriteRule ^stations[/]?$ requesthandlers/controller.php?page=stations [QSA,NC,L]
RewriteRule ^route/(.*)/(.*)/$ requesthandlers/controller.php?page=routeresult&from=$1&to=$2 [QSA,NC,L]
RewriteRule ^board/([^/]*)/$ requesthandlers/controller.php?page=boardresult&station=$1 [QSA,NC,L]
RewriteRule ^board/([^/]*)/(.*)/$ requesthandlers/controller.php?page=boardresult&station=$1&destination=$2 [QSA,NC,L]

现在我有以下几行:

rewrite ^/?$                    /requesthandlers/controller.php?page=route                                      last;
rewrite ^/route/?$              /requesthandlers/controller.php?page=route                                      last;
rewrite ^/board/?$              /requesthandlers/controller.php?page=board                                      last;
rewrite ^/settings/?$           /requesthandlers/controller.php?page=settings                                   last;
rewrite ^/stations/?$           /requesthandlers/controller.php?page=stations                                   last;
rewrite ^/route/(.*)/(.*)/?$    /requesthandlers/controller.php?page=routeresult&from=$1&to=$2                  last;
rewrite ^/board/(.*)/?$         /requesthandlers/controller.php?page=boardresult&station=$1                     last;
rewrite ^/board/(.*)/(.*)/?$    /requesthandlers/controller.php?page=boardresult&station=$1&destination=$2      last;

然而,它们似乎没有正常工作,虽然我没有收到任何错误。

1 个答案:

答案 0 :(得分:1)

rewrite ^/$ /requesthandlers/controller.php?page=route last;
rewrite ^/(route|board|settings|stations)(?:/|)$ /requesthandlers/controller.php?page=$1 last;
rewrite ^/route/([^/]+)/([^/]+)(?:/|)$ /requesthandlers/controller.php?page=routeresult&from=$1&to=$2 last;
rewrite ^/board/([^/]+)(?:/|)$ /requesthandlers/controller.php?page=boardresult&station=$1 last;
rewrite ^/board/([^/]+)/([^/]+)(?:/|)$ /requesthandlers/controller.php?page=boardresult&station=$1&destination=$2 last;