【问题标题】:Convert Apache rewrite conditions to Nginx将 Apache 重写条件转换为 Nginx
【发布时间】:2014-11-10 01:37:15
【问题描述】:

我花了一个半小时试图让以下重写规则在 Nginx 中正常工作,但我所做的一切都无法正常工作!它要么总是以无限重定向循环或 404 结束。

原来的 .htaccess 是这样的:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(js|ico|txt|gif|jpg|png|css|php)
RewriteCond %{REQUEST_URI} !=/server-status
RewriteRule ^(.*)$ index.php/$1/

AcceptPathInfo On

我已设置正确的 FastCGI 路径信息拆分参数 (fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;),但我无法让重定向规则/try_files 规则正常工作!

【问题讨论】:

    标签: .htaccess mod-rewrite nginx url-rewriting


    【解决方案1】:

    看起来你需要经典的 index.php 处理程序,但这只是配置的一部分,也许你需要更多配置:

    server {
    ...
    
      location /
      {
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php?$1 last;
        }
      }
    
      location ~* \.(js|ico|txt|gif|jpg|png|css)$ {
        expires 31d;
        access_log off;
      }
    
      location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass backend;
      }
    ...
    }
    

    【讨论】:

      猜你喜欢
      • 2012-02-25
      • 1970-01-01
      • 1970-01-01
      • 2016-06-18
      • 1970-01-01
      • 1970-01-01
      • 2015-02-19
      • 2012-09-02
      相关资源
      最近更新 更多