The issue you're experiencing is likely related to how Nginx is configured to handle requests to directories without a trailing slash. When you visit test.com/test_folder, Nginx might be treating it as a directory request and not automatically appending /index.php to the URL, which is why it works when you explicitly visit test.com/test_folder/index.php.
To resolve this, you can adjust your Nginx configuration to ensure that requests to directories automatically append /index.php if it exists. Here's how you can modify your Nginx configuration:
-
Open your Nginx configuration file. This is usually located at
/etc/nginx/sites-available/defaultor a similar path depending on your server setup. -
Find the server block handling your domain and add the following configuration:
location /test_folder {
index index.php;
try_files $uri $uri/ /test_folder/index.php?$query_string;
}
- Save the changes and restart Nginx to apply the new configuration:
sudo systemctl restart nginx
This configuration does the following:
- Sets
index.phpas the default file to serve when a directory is requested. - Uses
try_filesto attempt to serve the requested URI, then the URI with a trailing slash, and finally falls back toindex.phpwith any query string parameters.
By making these changes, visiting test.com/test_folder should now correctly serve index.php without needing to explicitly include it in the URL.