2012-09-24 84 views
1

任何人都可以幫助我嗎?apache多個重寫條件到nginx

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; 
    } 
    } 
} 

回答

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; 
} 
0

嘗試改變~* !!~*,並結合過去的2:

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; 
} 
+0

第一個將無法正常工作,因爲nginx的不接受嵌套。 – Arwed