In the beginning, I wanted to directly prohibit the URL of the PHP suffix from being accessed in the rewrite rules. But it turns out that rewrite rules are recursively invoked, and if PHP is banned directly in rewrite rules, then rules that rewrite to PHP files will fail. Rewriteengineon
REWRITERULE^TEST$/TEST.PHP[L]
REWRITERULE^TEST.PHP$$0[F,L]
Recursive call this is terrible, when you start to access the/test URL rewrite is checked once and then matched to ^test$ for internal redirection to/test.php, however internal redirection also triggers URL rewriting, so check again, match to ^test.php$, be forced directly [F] ( Forbidden) operation, so it becomes a 403 error. In this case, you must determine whether you have been redirected to the server. There's a redirect_url in the server variable, so I try to use that as a judge.
Rewriteengineon
REWRITERULE^TEST$/TEST.PHP[L]
rewritecond%{redirect_url}^$
REWRITERULE.*$0[F,L] Such write access/test is still 403, a little check, found that Rewritecond%{redirect_url} is always empty, this is the egg pain, so that in the rewrite rules can not directly prohibit PHP. But it can be accomplished in a less gorgeous way. is in the PHP file to Judge Redirect_url, although this method can be achieved, but the feeling is very lame, but so far did not find any better way.
$_server[' Redirect_url ']ordie (' forbidden ');
Here is only the display of text, the actual use of the time you need to output the HTTP error code.
echo$_server[' Redirect_url '];//successful access to display information
?>
This section of the PHP code into the global reference is basically no problem, although not a perfect solution, but at least it is resolved, later may find a better way.