首页 > 解决方案 > Apache 到 NGINX 重写问题

问题描述

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

阿帕奇规则: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 规则。

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

标签: apachenginx

解决方案


使用转换器

server {
    server_name example.com;

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

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


推荐阅读