I'm trying to set up mod_rewrite for my site and have a few questions.

I have rewritten URLs so that they are easy to read and understand. I would like to have a rule that would redirect someone trying to directly access php scripts to an error page. For example, going to www.domain.com/blog/ will show blog.php, but when the user tries to go to www.domain.com/blog.php, they will be sent to www.domain.com/error/.

RewriteCond %{REQUEST_URI} .php
RewriteRule ^$ /error/ [R=301]

It doesn't work, and doesn't seem right. Any idea how this can work?

Also, I have a folder with all of my scripts that are accessed with AJAX. Is there a way to prevent access to these scripts directly as well? Maybe something like redirecting to /error/ if the request is not an XMLHTTPRequest, or is this more of a mod_access thing? I'm not familiar with mod_access though, and would appreciate any help you can give with that as well.

I have a folder with all of my scripts that are accessed with AJAX. Is there a way to prevent access to these scripts directly as well?

I doubt it, there would have to be something unique sent in the request headers for it to know that it was an AJAX request. You could do hotlink protection type referrer checking but it is unreliable, in a .htaccess file in the directory

An example of what I'm trying to do for protecting the ajax scripts is on reddit.com. Using firebug, you can see that voting on an article makes an ajax request to http://reddit.com/api/vote. But, when you navigate to that link, you see a 404 page not found page. I'm trying to figure out how this is done. Any help is much appreciated!

I have a folder with all of my scripts that are accessed with AJAX. Is there a way to prevent access to these scripts directly as well?

I doubt it, there would have to be something unique sent in the request headers for it to know that it was an AJAX request. You could do hotlink protection type referrer checking but it is unreliable, in a .htaccess file in the directory

hi,i just tried all the above to remove the .php extention and prevent anyone to use the .php extention on my site. but it doesn't work. it always shows NOT FOUND page,i'm only using this code to remove the .php extention from my URLs regarding if they are somepage.php or somepage.php?action=something