真的很简单的Nginx重写到index.php需要,无法找到解决方案

时间:2012-04-11 13:07:52

标签: php nginx web rewrite

我使用了.htaccess到nginx重写转换器,解决方案无效。事实上,无论我尝试什么,我都无法让任何重写工作。我显然在这里做错了什么。

我想将除PHP请求之外的所有请求重定向到index.php文件并使用PHP解析请求(无论文件/文件夹是否存在)。

这是我的简约Nginx.conf文件:

worker_processes  1;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        # Make sure to set this as your actual server WWW root
        root html;
        # Index file
        index index.php;
        # Rewrite that directs everything to index file
        rewrite /!^(.*).php$ /./index.php last;

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

我甚至尝试过像#34;重写index.php"没有成功。我也尝试将重写放在一个单独的位置标记中,但这也没有区别。

我想将除PHP请求之外的所有请求重定向到index.php文件并使用PHP解析请求(无论文件/文件夹是否存在)。

除了没有足够的Nginx经验之外,我做错了什么?

原始.htaccess文件:

Options +FollowSymLinks 
RewriteEngine on
RewriteRule !^(.*)\.php$ ./index.php [QSA,L]

0 个答案:

没有答案