I have the following .htaccess file for my website:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /$1.php [R=301,L,QSA]
This works, in that the url 'hello' works, as well as 'hello.php'. What I want to do, however, is the following:
- Remove .php from 'hello.php' and redirect to 'hello'.
- Remove (and redirect) trailing slash (if any).
How can this be done? I imagine it is quite simple.
EDIT: I was just working on this and it also has a redirect loop if you browse to 'hello.p' and if you browse to 'hello/'.
Your current rule is instructing Apache to 301 redirect to the route with the
.php
extension.To prevent this, you'll need to remove the
R=301
from the flag list.