I have got a website where all of the pages are php scripts, therefore the Web addresses finish .php.

I have added the next to some .htaccess file, and that i are now able to access the .php files with no .php extension:

RewriteEngine On  # Turn on rewriting

RewriteCond %{REQUEST_FILENAME}.php -f  # If the requested file with .php on the end exists
RewriteRule ^(.*)$ $1.php #  serve the PHP file

To date so great. However I wish to give a Redirect on all of the .php files to ensure that any links outdoors of my control get rerouted towards the latest version from the URL.

I have attempted this:

RewriteEngine On  # Turn on rewriting

RewriteCond %{REQUEST_URI} .*\.php
RewriteRule ^(.*)\.php$ http://example.com/$1 [R=permanent,L]

RewriteCond %{REQUEST_FILENAME}.php -f  # If the requested file with .php on the end exists
RewriteRule ^(.*)$ $1.php [L] #  serve the PHP file

but that appears to transmit a redirect for Web addresses that do not finish insperl, and so i really go to town an infinite loop. Every other combination I attempt appears to complement no demands (and then leave me at page.php) or all demands (and obtain me stuck inside a loop).

RewriteEngine On

RewriteCond %{THE_REQUEST} ^\w+\ /(.*)\.php\ HTTP/
RewriteRule ^ http://%{HTTP_HOST}/%1 [R=301]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* $0.php

Only %{THE_REQUEST} isn't rewritten within the internal redirection that occurs within the second rule (%{REQUEST_URI}, however, is).

You redirecting pages ending with .php towards the page without .php

Your first rule rewites all pages not ending with .php towards the page title ending with .php

For this reason you've got a loop :-)

Add NS to parameters listing of that last rule

You may have the ability to include [L] towards the RewriteRule for adding .php, to ensure that it stops processing another Rules:

RewriteRule ^(.*)$ $1.php [L] #  serve the PHP file

Because of a pointer to this question by @TheDeadMedic, I found a strategy to my very own problem by altering:

RewriteCond %{REQUEST_URI} .*\.php

to:

RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP

I do not realise why my version did not perform the same factor, though.