in my website i have only two pages "index.php" and "page.php", whatever i type i get redirected to localhost, for instance if i go to localhost/randompage instead of being redirected to 404.html i go to localhost (i.e index.php)
here is my conf:
server {
listen 80;
server_name localhost;
root html;
index index.php;
location / {
if ($request_uri !~* '\/|page\.php\?.*') {
return 404;
}
try_files $uri $uri/ /index.php;
}
error_page 404 /404.html;
location = /404.html {
root html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
what should i change?
I had a similar problem. Commenting out this line fixed it:
try_files $uri $uri/ /index.php;
try_files checks to see if the given URI works. If not, it tries to see if the given URI works as a directory. Failing that, it redirects to /index.php. Without this line, it'll serve up the 404 file indicated with error_page.
Hope that works for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With