2

I'm working on some old PHP code of mine that was previously served using Apache+Multiviews+PATH_INFO. I'm now trying to get this site up and running using nginx (which I use and adore for all of my other more recent work).

The issue is with URLs such as /books/newreleases/1420, which actually needs to be handled by /books.php (so that php sees /books.php/newreleases/1420 with appropriate PATH_INFO info available).

I know all of the reasons why such use of multiviews is a bad idea, but redeveloping this site to work around it is not currently an option.

I can make this specific example work through use of rewrite: (rewrite ^/books/(.*)$ /books.php/$1;) but there are too many files across the entire site to make manual coding of rewrites for each anything other than a last resort. Plus, it makes me sad.

I've been reading through all of the similar questions on here but can't find an answer to this specific case, nor can I quite figure out if there's a correct way to use try_files to handle it.

Here's the meat of my config as it stands:

server {
    server_name foo.com www.foo.com;
    root /srv/www/foo.com/public_html;
    rewrite_log on;
    index index.html index.htm index.php;

    location / {
        rewrite ^/books/(.*)$ /books.php/$1;
        try_files $uri $uri.php $uri/ =404; 
   }

    location ~ ^.+\.php {
        try_files $uri.php $uri/ =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9050;
        fastcgi_index index.php;
        fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    }
}
patrick
  • 31
  • 4

0 Answers0