Q:

Advanced htaccess Redirection

Using mod_rewrite, I have a series of server-side redirects (Meaning that the client is not made aware of the URI changes.)  I want to make it so that any client-side references to index.php return a 404 error without disruption to the server-sided requests...
--
Example..
Client requests x.html, it loads the content of index.php..
Client requests index.php, client gets a 404 Not Found error..
--
I understand that this is poorly formed and could probably be explained a lot better but I'm hoping that this is explained well enough - if it's not, I apologize...
--
I've spent the last three hours on google, trying to find the solution to this and have come up short as I don't really know what it would be understood as...

A:

The answer depends on your context : if you are NOT in a .htaccess or in a <Directory>, this is easy :
RewriteEngine On
RewriteRule  /index.php     -           [L,R=404]
RewriteRule  /x.html        /index.php  [L]

If you are in a .htaccess or in a <Directory>, the request is processed a second time, see here.
I used an environment variable to work around that :
RewriteEngine On
# after an internal redirect, the variable is prefixed with REDIRECT_
RewriteCond %{ENV:REDIRECT_redirect_to_php} !=true
# no leading / this time
RewriteRule  index.php     -           [L,R=404]
RewriteRule  x.html        /index.php  [L,E=redirect_to_php:true]

You can use RewriteLog and RewriteLogLevel to get the details of the rewrite execution.

