0

If the user types www.mysite.com/foo.php, if the file foo exist the server respond with foo, but if the file does not exist, it needs to rewrite like this: www.mysite.com/url.php?url=foo.php

Im trying this on nginx:

    location / {
            include /etc/nginx/global/*;
            #try_files $uri $uri/ /index.html;

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

But instead of rendering the page (when the file is not present), the browser downloads it. Why?

2
  • You need to be using try_files, not rewrite. Aug 4, 2015 at 20:25
  • @MichaelHampton can you please give an example?
    – DomingoSL
    Aug 4, 2015 at 20:37

2 Answers 2

0

You must add location for processing .php files, if not yet. And setup php-fpm too, of course.

location / {
    include /etc/nginx/global/*;
    try_files $uri $uri/ /url.php?url=$uri;
}

# something about
location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi_params;
}
0

Something like

try_files $uri $uri/ /url.php?url=$uri;

Should do the trick.

2
  • how can I handle index.html?
    – DomingoSL
    Aug 5, 2015 at 14:49
  • What about index.html?
    – womble
    Aug 5, 2015 at 23:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .