I have a small problem with a rewrite rule not applying to sub-directories. What I'm doing is trying to hide .php file extensions. After several days of trying to get this to work along with a combination of other rewrites I've almost managed to get this working (with the kind help from people in this forum) however I have one final issue to clear up.
Almost everything is working correctly, however .php file extensions are still required within sub-directories, so for example summeraway.com/browse will work, but summeraway.com/manage/add won't
I tried fixing this myself only to stop another of the rewrites from working (the /holiday-villa-rental/ rewrite). Hopefully someone can find a solution, after 3 days of frustration I'd be extremely grateful!
Thanks
- Code: Select all
Options +FollowSymLinks
RewriteEngine On
# remove (root) php file extensions
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
# force (root) trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301]
# specific rules
RewriteRule ^holiday-villa-rental/([0-9]+)/$ /holiday-villa-rental/?id=$1
RewriteRule ^holiday-villa-rental/([0-9]+)/([0-9]+)/$ /holiday-villa-rental/?id=$1&photo=$2
# send php requests to /notfound/
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)\.php$ /notfound/ [QSA,L]