I rewrite my .php files to .htm, using the following code in .htaccess file.

RewriteEngine on
Options +FollowSymlinks
RewriteRule ^(.+)\.htm$ $1.php [NC]

This is working fine. But now I want to restrict access of .php file directly.
As example: when people request index.htm he can see the content of index.php file, but if he request index.php then he will get an 404 error. How is it possible?


1 Answer 1

RewriteRule .*\.php /404.htm

That's untested but basically I would redirect *.php to 404.htm and then create a 404.php to cater for that. Put this rule above your .htm to .php rule.

  • This is throwing an Internal Server Error. Error Details: "Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request." Dec 12, 2010 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.