【问题标题】:Apache to NGINX Rewrite IssueApache 到 NGINX 重写问题
【发布时间】:2020-05-12 13:09:00
【问题描述】:

我正在尝试将此 apache ReWriteRule 转换为 NGINX,但它似乎不起作用。

Apache 规则:RewriteRule ^([A-Za-z0-9_-]+)\.php$ index.php?pagename=$1 [NC,QSA]

NGINX(不工作):location / { rewrite ^/([A-Za-Z0-9_-]+)\.php? /index.php?pagename=$1; }

我确实在位置块中有 NGINX 规则。

我在这里缺少什么?我查看了其他类似的问题,但没有找到足够的合适线索来解决问题。感谢您的帮助。

【问题讨论】:

  • 它可能在错误的location 块中。是否有一个位置块可以处理任何以.php 结尾的 URI? rewrite 语句需要位于选择用于处理原始请求的 location 块中,或者位于 server 块中。
  • 我会检查一下,看看会发生什么。

标签: apache nginx


【解决方案1】:

使用converter

server {
    server_name example.com;

    rewrite ^/([A-Za-z0-9_-]+)\.php$ /index.php?pagename=$1;
}

事实上,只需将rewrite 放在server {} 上下文中(不需要无关的location),许多重写就更容易了。

【讨论】:

    猜你喜欢
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    • 2010-10-01
    相关资源
    最近更新 更多