0

I have written a rule that allows my .php pages to be viewed without the file extension.

e.g.

/test-page.php is rewritten to /test-page/

I'm also redirecting non www to www. However, if I try to directly access test-page.php this doesn't get redirected - am I missing anything obvious?

RewriteEngine On

RewriteCond %{HTTP_HOST} ^mysite.co.uk [NC]
RewriteRule ^(.*)$ https://www.mysite.co.uk/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
user319940
  • 3,267
  • 8
  • 38
  • 53

1 Answers1

0

Check this one. The idea was taken from 4026021.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.co.uk [NC]
RewriteRule ^(.*)$ https://www.mysite.co.uk/$1 [L,R=301]
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
Elvis Plesky
  • 3,190
  • 1
  • 12
  • 21