任何人都可以帮我吗?
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;
}
}
}
答案 0 :(得分: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;
}
答案 1 :(得分: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;
}