I have a problem with two rewrites transfering a sito from an apache hosting to an nginx hosting. 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.
apache rewrite
RewriteRule ^news/([^/]+)/([^/]+)/([^/]+)\.html$ news_dett.php?l=$1&par=$2&titolo=$3 [L]
result apache
exampleSite/news/it/44/Title_Of_the_news.html
apache rewrite
RewriteRule ^Research-and-develop\.html$ researchdevelop?l=$1 [L]
result apache
exampleSite/Research-and-develop.html
nginx rewrite
location /news {
rewrite ^/news http://$http_host/news_dett.php?l=$1&par=$2&titolo=$3 redirect;
}
result nginx
Clicking on link exampleSite/news/it/44/Title_Of_the_news.html
we go to exampleSite/news_dett.php?l=&par=&titolo=
In fact this doesn't work at all
nginx rewrite
location /Research {
rewrite ^/Research-and-develop\.html$ http://$http_host/researchdevelop?l=$1 redirect;
}
result nginx
clicking on link exampleSite/Research-and-develop.html
we go to exampleSite/researchdevelop.php?l=
Can you help set the correct rewrite mode for nginx?
Your /news
rewrite is missing the captures for $1
and $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. 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.
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). An alternative to an exact match rewrite
directive would be an exact match location:
location = /Research-and-develop.html {
rewrite ^ /researchdevelop?l= last;
}
See also rewrite
documentation , location
documentaion , and a useful regular expression resource .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.