'.htaccess redirects not working on localhost

I have the following .htaccess which is supposed to open /index.php for ALL requests, regardless of whether the requested folder or file exists:

RewriteEngine On
RewriteRule . index.php [END]

Unfortunately, this doesn't work on my localhost:

  • http://localhost:9000/file -> opens /index.php (GOOD)
  • http://localhost:9000/folder/file -> opens /index.php if /folder/ doesn't exist (GOOD)
  • http://localhost:9000/folder/file -> "Not Found" if /folder/ exists (BAD)
  • http://localhost:9000/file.php -> opens the file if it exists and gives a "Not Found" if it doesn't exist (BAD)
  • http://localhost:9000/folder/file.php -> opens the file if it exists and gives a "Not Found" if it doesn't exist (BAD)

My localhost is running on macOS via php -S localhost:9000 in Terminal.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source