A site has its URLs with php extensions, like this: example.com/page.php
I used the following rewrite to remove the extension so that the page can now be accessed from example.com/page
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
It works great. I can access it via the example.com/page URL.
However, the problem is the page can still be accessed from example.com/page.php. Because I have external links going to the page, I want to 301 redirect example.com/page.php to example.com/page. I've tried this a couple of ways but I get redirect loops or 500 internal server errors.
Is there a way to have both? Remove the extension and 301 the .php to no extension?
By the way, if it matters, page.php is an actual file in the root directory (not created through another rewrite or URI routing).
I'm hoping I can do this, and not just throw a example.com/page canonical tag on the page.
Thanks!