簡體   English   中英

Mod從Apache重寫為Nginx

[英]mod rewrite from apache to nginx

我在將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;
}

但它不能與htaccess中的內容100%相同。

您可以在Nginx中使用位置塊。 這會將您的所有請求重定向到index.php。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM