首页 > 解决方案 > NGINX / Apache 重写规则

问题描述

我需要一些 NGINX / Apache 的重写规则(目前正在使用 NGINX,但取决于我的老板,它可能稍后会更改为 Apache)。

规则应该使服务器解释 URL 如下:

https://domain.tld/signin
https://domain.tld/hello/world
https://domain.tld/user/john/doe

像这样:

https://domain.tld/index.php?lvl1=signin
https://domain.tld/index.php?lvl1=hello&lvl2=world
https://domain.tld/index.php?lvl1=user&lvl2=john&lvl3=doe

(或类似的东西,它不一定是 lvl1、lvl2、lvl3 ......但我可以使用的东西)。

我也面临两个问题:

  1. 应排除在域之后直接以 a 开头的文件路径/static/,以便在 HTML 文件中正确传递链接的 CSS、JS、PDF、图像、视频...。
  2. 常规 GET 参数应该仍然可以正常工作,就好像它们没有被触及一样。类似的 URL/foo/bar?action=edit仍应解释为/lvl1=foo&lvl2=bar&action=edit

有没有人可以帮助我处理 NGINX 和 Apache 的这些规则?我已经搜索了很长时间,但没有找到令人满意的解决方案。

标签: apachenginxurlurl-rewritingconfig

解决方案


推荐阅读