In reply to:
1) RewriteEngine On
2) RewriteCond %{REQUEST_FILENAME} ! -f
3) RewriteCond %{REQUEST_FILENAME} ! -d
4) RewriteRule (.*) /404.PHP [L]
Can someone please explain to me exactly what that would do
I've numbered the lines for ease of reference. 1 tells Apache to turn on mod_rewrite, which is a module that allows you to do regular expression based search and replace on URLs requested by your users. 2 and 3 check to make sure that what the user asked for is neither a file nor a directory, respectively (in other words, that the user asked for something that doesn't exist). 4 tells Apache to load and execute 404.PHP from your root directory regardless of what the user asked for. Logically, the way you read that is, "If 2 and 3, then 4," or in English, "If the user asked for something that is not a file and is not a directory, then run /404.PHP"
In reply to:
if someone asks for a page.htm and there is no such page, give them page.php
Given the above, we can rephrase what you want to tell the system to do as follows: "When the user asks for page.htm, if page.htm is not a file and page.htm is not a directory, then run page.php" I assume, further, that 'page.htm' is just an example, and what you really want is any .htm or .html page (*.htm or *.html). This is something regular expressions make easy:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} ! -f
RewriteCond %{REQUEST_FILENAME} ! -d
RewriteRule ^(.*)\.html?$ /$1.PHP [L]
As you can see, the first three lines are the same, just as the rephrased question started out the same. The bottom line says the following: "Start at the beginning of the requested file path and name and look for .htm or .html at the end. If you find .htm or .html at the end, put everything before the dot into $1. Then, invoke the PHP script with the same path and name."
Note that the parentheses determine what gets thrown into $1 -- everything up to but not including the .htm becomes part of $1. To use this method, your PHP script must be at the same place in the filesystem as your HTML was originally.