简体   繁体   English

Apache 到 NGINX 重写问题

[英]Apache to NGINX Rewrite Issue

I'm trying to convert this apache ReWriteRule to NGINX but it doesn't seem to be working.我正在尝试将此 apache ReWriteRule转换为 NGINX 但它似乎不起作用。

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

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

I do have the NGINX rule in a location block.我确实在位置块中有 NGINX 规则。

What am I missing here?我在这里想念什么? I looked at the other similar questions but didn't find enough suitable clues to solve the problem.我查看了其他类似的问题,但没有找到足够的合适线索来解决问题。 Thanks for the help.谢谢您的帮助。

Using converter :使用转换器

server {
    server_name example.com;

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

And indeed, many rewrites are easier with just a rewrite placed in the server {} context (no need for extraneous location ).事实上,只需将rewrite放在server {}上下文中(不需要无关的location ),许多重写就更容易了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM