简体   繁体   English

将Apache重写为Nginx

[英]rewrite apache to nginx

this is my first time with nginx rewrite, who can help me convert those rules to nginx sintax? 这是我第一次使用nginx重写,谁能帮助我将这些规则转换为nginx sintax?

RewriteRule (economics|sport|gossip|aboutus)+$ index.php?section=$1
RewriteRule (register)+$ $1.php?%{QUERY_STRING}
RewriteCond %{QUERY_STRING} ^p
RewriteRule (economics|sport|gossip)/+$ articles.php?section=$1&%{QUERY_STRING}

thank you 谢谢

rewrite (economics|sport|gossip|aboutus)$ /index.php?section=$1 last;

I'm not sure what the purpose of the + is in your original regex. 我不确定+在原始正则表达式中的作用是什么。 Can there be more than one of the four words? 四个单词中可以有多个吗? Have you tried matching for just one of those words (ie is the problem the "or" part)? 您是否尝试过仅匹配其中一个单词(即问题是“或”部分)? Why "break" instead of "last" for the rewrite directive ? 为什么重写指令是 “ break”而不是“ last”?

rewrite (register)+$ $1.php last;

Again, I'm not sure what you're trying to accomplish with the + in this regex. 同样,我不确定您要使用此正则表达式中的+来完成什么操作。 Do you mean .+ (that is, "one or more of any character")? 您是说.+ (即“任何一个或多个字符”)吗? If so, the $ is superfluous. 如果是这样,则$是多余的。 As you've written it, it means "one or more repetitions of the string 'register' ending the request string." 如您所写,它的意思是“对请求字符串结尾的字符串'register'进行一次或多次重复”。

The rewrite syntax in nginx is not too entirely different. nginx中的重写语法没有太大的不同。

rewrite  ^/(.*)$  http://www.just1word.com/$1  permanent;

This is one taken from a config file that I have laying around. 这是我配置的一个配置文件中的一个。 Perhaps it will point you in the right direction. 也许它将为您指明正确的方向。

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

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