【问题标题】:Apache to nginx - htaccess doesn't work, nor does trying to convertApache 到 nginx - htaccess 不起作用,也没有尝试转换
【发布时间】:2012-03-05 15:07:00
【问题描述】:

我正在尝试使用通常在 nginx 上的 Apache 上运行的内部框架。我一直没有运气转换 htaccess。

我试过http://www.anilcetin.com/convert-apache-htaccess-to-nginx/ 无济于事。然后我自己做了(想出了不同的规则),这也不起作用。这是我目前拥有的:

            index index.php;

            location / {
                    if ( !-e $request_filename ) {
                            rewrite ^(.*)$ /index.php?$1 last;
                            break;
                    }
                    rewrite ^/$ /? last;
            }

            location ~ ^/(assets|robots\.txt|favicon\.ico|license.txt) {

            }

             location ~ \.php$ {
              fastcgi_pass   unix:/var/run/php5-fpm.sock;
              fastcgi_index index.php;
              fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
             }

我要转换的 htaccess 是:

DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico|license.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA] 
RewriteCond %{QUERY_STRING} .
RewriteRule ^$ /? [L]

会有人碰巧知道出了什么问题或我应该怎么做吗?

谢谢!

【问题讨论】:

    标签: apache .htaccess nginx


    【解决方案1】:

    你几乎不应该在 Nginx 配置中使用 if。试试这个-

    location / {
        try_files $uri /index.php;
    }
    

    剩下的不是重写某些文件,因此不需要长的丑陋的正则表达式位置块。

    【讨论】:

      猜你喜欢
      • 2017-02-05
      • 2015-05-21
      • 2011-11-25
      • 1970-01-01
      • 2021-11-26
      • 2015-07-08
      • 2020-12-23
      • 2011-08-21
      • 2020-09-22
      相关资源
      最近更新 更多