1

谁能帮我这个?

RewriteCond %{REQUEST_URI} !^\/index\.php$
RewriteCond %{REQUEST_URI} !^\/search\/.*
RewriteCond %{REQUEST_URI} ^\/([^/]*)\.php$
RewriteRule (.*) http://www.mydomain.com/index.php?page=$1

我需要将其转换为 nginx

我试过这个,但它不起作用:

if ($request_uri ~* !^\/search\/.*) {
  if ($request_uri ~* !^\/index\.php$) {
    if ($request_uri ~* ^\/([^/]*)\.php$) {
      rewrite (.*) http://www.mydomain.com/index.php?page=$1;
    }
  }
}
4

2 回答 2

1

我最终使用:

if ($uri !~ "^/index.php$") {
  set $rule_0 1$rule_0;
}
if ($uri !~ "^/search/.*") {
  set $rule_0 2$rule_0;
}
if ($uri ~ "^/([^/]*).php$") {
  set $rule_0 3$rule_0;
}
if ($rule_0 = "321") {
  rewrite ^(.*) /index.php?page=$1 last;
}
于 2012-09-25T06:50:23.130 回答
0

尝试将 更改~* !!~*,并结合最后两个:

if ($request_uri !~* ^/search/.*) {
  if ($request_uri !~* ^/index\.php$) {
    rewrite ^/([^/]*)\.php$ http://www.mydomain.com/index.php?page=$1 redirect; 
  }
}

或坚持基于位置的规则:

location ~ /index\.php$ { } 
location ~ /search/.* { } 
location / { 
    rewrite ^/([^/]*)\.php$ http://www.mydomain.com/index.php?page=$1 redirect; 
}
于 2012-09-24T16:28:50.507 回答