简体   繁体   English

将重写规则从apache传输到nginx

[英]transfer rewrite rule from apache to nginx

I have a problem with two rewrites transfering a sito from an apache hosting to an nginx hosting. 我有两次重写问题,将一个Apache服务器从Apache主机转移到Nginx主机。 I've tried reading online, this is the best that i've come up with, unfortunately I have little practice with regexp and rewrites on nginx, please help. 我尝试过在线阅读,这是我想出的最好的方法,但是不幸的是,我很少使用regexp并在nginx上进行重写,请提供帮助。

apache rewrite apache重写

RewriteRule ^news/([^/]+)/([^/]+)/([^/]+)\.html$    news_dett.php?l=$1&par=$2&titolo=$3 [L]

result apache 结果Apache

exampleSite/news/it/44/Title_Of_the_news.html

apache rewrite apache重写

RewriteRule ^Research-and-develop\.html$     researchdevelop?l=$1 [L]

result apache 结果Apache

exampleSite/Research-and-develop.html

nginx rewrite Nginx重写

location /news {
     rewrite ^/news http://$http_host/news_dett.php?l=$1&par=$2&titolo=$3 redirect;
    }

result nginx 结果nginx

Clicking on link exampleSite/news/it/44/Title_Of_the_news.html we go to exampleSite/news_dett.php?l=&par=&titolo= 单击链接exampleSite/news/it/44/Title_Of_the_news.html我们转到exampleSite/news/it/44/Title_Of_the_news.html exampleSite/news_dett.php?l=&par=&titolo=

In fact this doesn't work at all 实际上,这根本不起作用

nginx rewrite Nginx重写

location /Research {
            rewrite ^/Research-and-develop\.html$ http://$http_host/researchdevelop?l=$1 redirect;
    }

result nginx 结果nginx

clicking on link exampleSite/Research-and-develop.html we go to exampleSite/researchdevelop.php?l= 单击链接exampleSite/Research-and-develop.html我们转到exampleSite/researchdevelop.php?l=

Can you help set the correct rewrite mode for nginx? 您可以为Nginx设置正确的重写模式吗?

Your /news rewrite is missing the captures for $1 and $2 . 您的/news重写缺少$1$2的捕获。 The scheme and server parts are unnecessary when redirecting to the same server. 重定向到同一服务器时,不需要方案和服务器部分。 Also, last performs an internal redirect, which avoids exposing the rewrite to the customer. 此外, last执行内部重定向,从而避免了将重写内容暴露给客户。 It should look like this: 它看起来应该像这样:

rewrite ^/news/([^/]+)/([^/]+)/([^/]+)\.html$ /news_dett.php?l=$1&par=$2&titolo=$3 last;

Optionally placed inside a location /news { ... } block. (可选)放置在location /news { ... }块中。

It is not clear from your question as to the value of $1 in the second rewrite rule (I am assuming that it is empty). 从您的问题不清楚第二重写规则中的$1的值(我假设它为空)。 An alternative to an exact match rewrite directive would be an exact match location: 完全匹配rewrite指令的替代方法是完全匹配位置:

location = /Research-and-develop.html {
    rewrite ^ /researchdevelop?l= last;
}

See also rewrite documentation , location documentaion , and a useful regular expression resource . 另请参见rewrite文档location文档和有用的正则表达式资源

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

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