-1

我使用在线转换器将以下 Apache mod_rewrite 转换为 NginX 重写:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1 [R=301,L]

输出如下所示:

  if (!-f $request_filename){
        set $rule_0 1$rule_0;
}
if (!-d $request_filename){
        set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
        rewrite /. /index.php last;
}
if ($http_host ~* "^www.(.*)$"){
        set $rule_1 1$rule_1;
        set $bref_1 $1;
}
if ($rule_1 = "1"){
        rewrite ^/(.*)$ http://$bref_1 permanent;
}

虽然转换在添加到 vhosts 文件时有效,但有人向我指出转换很差,而且http://docs.ngx.cc/en/latest/topics/depth/ifisevil.html

有人可以帮我“正确”转换吗?

谢谢你。

4

1 回答 1

0

这主要应该解决问题,问题在于你想要传递给什么index.php

server {
    server_name example.com;
    root /path/to/www;
    location / {
        try_files $uri $uri/ /index.php$request_uri
    }
}
server {
    server_name www.example.com;
    return 301 example.com;
}
于 2013-09-12T21:34:03.600 回答