deny direct access to a folder and file by htaccess

Here is the scenario:

  • There is a index.php file in root folder
  • some files are included in index.php which are in the includes folder.
  • 1 other file (submit.php) is in the root folder for form submit action.

I want to restrict direct user access to the files in includes folder by htaccess. also for submit.php. But include will work for index.php file. Like, if user types www.domain.com/includes/somepage.php, it will restrict it (may be redirect to a error page).

Force Forward xxx.php URLs to xxx using .htaccess

I have a site that I've been running for years with the .php as part of the URL. I want to switch it over. But there are existing links out there that contain the .php in it. IMPORTANT: I think a lot of people are quickly assuming that I'm asking the trivial question of "how do I remove .php from my URL?" which I already know how to do, and it already works. My question is not quite that, so please read through carefully. This is more related to existing links, and URL unification purposes.. for SEO.

Currently I have this in my .htaccess, so the URLs work without the .php already:

RewriteEngine On
Options +MultiViews

However, is there a way to detect when there is a .php included in the request and re-write the URL (or in other words, a straight up 301 forwarding) to a URL that omits the .php?

http://www.mydomain.com/our-services.php -> http://www.mydomain.com/our-services

After the suggestion from the 1st answer I cahnged it to this:

Options +MultiViews
RewriteEngine On 
RewriteBase / 

RewriteCond %{ENV:REDIRECT_STATUS} 200 
RewriteRule .* - [L]

RewriteRule ^(.+)\.php $1 [L,R=301]
RewriteRule ^(.+)$ $1.php [L]

RewriteCond %{HTTP_HOST} ^rhondasherwood\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

ErrorDocument 404 /notfound

Created an infinite redirect.