How can I resolve a 404 error when submitting a link or request in PHP on IIS?

When encountering a 404 error when submitting a link or request in PHP on IIS, it could be due to incorrect URL rewriting rules or a misconfiguration in the web server settings. To resolve this issue, ensure that the URL rewriting rules are properly set up in the web.config file and that the requested file or resource exists in the specified location.

// Sample PHP code to handle URL rewriting on IIS

if (!file_exists($_SERVER["DOCUMENT_ROOT"] . $_SERVER["REQUEST_URI"])) {
    // Handle 404 error here
    header("HTTP/1.0 404 Not Found");
    echo "404 Error - Page Not Found";
    exit();
}

// Continue with processing the request if the file exists