nginx サーバーに php と簡単な書き換えルールを設定したいと思います。存在しないファイルまたはディレクトリを指す URL は /index.php?q= に書き換えるという書き換えルールを作成しようとしました。このnginx.confを作成しました:
events {
}
http {
  include fastcgi.conf;
  server {
    listen          80;
    server_name     www.example.com;
    index           index.php;
    root            /var/www/html/www.example.com;
    location / {
      index     index.php;
      if (!-f $request_filename) {
        rewrite ^/(.*)$ /index.php?q=$1 last;
      }
      if (!-d $request_filename) {
        rewrite ^/(.*)$ /index.php?r=$1 last;
      }
    }
    location ~ \.php {
      try_files $uri =404;
      fastcgi_pass 127.0.0.1:9999;
    }
  }
}
これは機能しますが、すべての場合ではありません。tihs のように utl を完全に書き換えます。
http://www.example.com/111/222/333
しかし、2つのケースは私が望むようには機能しません:
http://www.example.com/111/222/333.php
404 エラーをドロップします。
また、www.example.com/forum/index.php が存在するので、www.example.com/forum/index.php はフォーラム ディレクトリで index.php を実行します。これで問題ありません。しかし、www.example.com/forum の URL は /index.php に書き換えられます。フォーラム ディレクトリで index.php を実行する必要はありません。
この2つの問題を解決するにはどうすればよいですか?
ありがとうございました!