【问题标题】:mod rewrite from apache to nginx从 apache 到 nginx 的 mod 重写
【发布时间】:2019-01-14 14:38:03
【问题描述】:

我在将 htaccess 从 apache 转换为 nginx 时遇到了一些麻烦。

实际htaccess规则:

options +followsymlinks
RewriteEngine On
RewriteCond $1 !^(images|system|themes|css|js|flex|slider|rss|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule ^(.*) /index.php?$1 [L]

此规则集用于表达式引擎 1.7

我目前的解决方案:

    location / {
    index index.php;
    try_files $uri $uri/ @ee;
}
location @ee {
    rewrite ^(.*) /index.php?/$1 last;
}
location /index.php {
    include fastcgi_params;
    set $script     $uri;
    set $path_info  $uri;
    if ($args ~* "^(/.+)$") {
       set $path_info  $1;
    }
    fastcgi_pass fastcgi-upstream_${server_name};
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $path_info;
}
location ~* \.php$ {
    include fastcgi_params;
    fastcgi_pass fastcgi-upstream_${server_name};
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_script_name;
}

但它并没有 100% 反映与 htaccess 中相同的东西。

【问题讨论】:

    标签: apache .htaccess nginx mod-rewrite


    【解决方案1】:

    您可以在 Nginx 中使用位置块。这会将您的所有请求重定向到 index.php。

    location / {
      rewrite ^/(.*) /index.php?$1 break;
    }
    

    【讨论】:

      猜你喜欢
      • 2019-12-19
      • 1970-01-01
      • 2011-03-17
      • 2011-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多