0

現在、私はこのコードを持っています:

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

これは、次の場合に問題 なく機能example.com/fooします。index.php

ただしexample.com/foo?bar、機能しません。どのように機能させますか?

FWIW: Apache の mod_rewrite に相当するものでは、この問題は発生しません。基本的に、動作するサイトをApacheからNginxに移動しました。今、私はこの問題を経験しています。

編集:

明確にするために、私がインデントすることは次のとおりです。

  • example.com/foo
  • example.com/foo/bar/etc
  • example.com/foo?bar
  • example.com/foo?bar=quz

index.phpブラウザのアドレスバーの URL を変更せずに、すべて「サイレント」にサービスを提供する必要があります。

4

1 に答える 1

1

次の構成でテストしましたが、これはあなたが望んでいると思います:

server {
#listen   80; ## listen for ipv4; this line is default and implied
#listen   [::]:80 default ipv6only=on; ## listen for ipv6

root /home/www/test;
index index.php index.html index.htm;

# Make site accessible from 
server_name test.myhost.nl;

location / {        
    # First attempt to serve request as file, then as directory, then fall back to index.php
    try_files $uri $uri/ /index.php?$args;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
    try_files $uri = 404;

    # Fix for server variables that behave differently under nginx/php-fpm than typically expected
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # Include the standard fastcgi_params file included with ngingx
    include fastcgi_params;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_index index.php;

    # Override the SCRIPT_FILENAME variable set by fastcgi_params
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    # Pass to upstream PHP-FPM; This must match whater you name your upstream connection
    #fastcgi_pass phpfpm;
    fastcgi_pass 127.0.0.1:9000;
}
}
于 2012-10-17T16:40:02.377 に答える