How to merge several HTAccess rewrites?

72 Views Asked by At

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:

  1. Remove .php from 'hello.php' and redirect to 'hello'.
  2. 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/'.

1

There are 1 best solutions below

0
On

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.