clashing htaccess rules .php file extention still accessible

Question!

I have been trying to get my urls re-written. The first 4 rules are vital, but they are clashing with this line: (i think).

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^.#?\ ]+)\.php([#?][^\ ]*)?\ HTTP/

this stops the url being able to be accessed like so www.example.com/page.php and redirects to www.example.com/page/

after adding the first 4 rules you can see in the htaccess, the above condition doesnt seem to work and Im able to access urls like this :(

lovelakedistrict.com/lake-district-cottages.php/cottages/5/

obviously i should be like this

lovelakedistrict.com/lake-district-cottages/cottages/5/

however this still works :)

lovelakedistrict.com/lake-district-cottages.php --> lovelakedistrict.com/lake-district-cottages/

This is my htaccess file- can anyone see what happening?

Options +FollowSymlinks
Options +Indexes

RewriteEngine on
#these 4 rules stop being able to access pages like eg
#/lake-district-cottages/?cottages=5/
#/lake-district-cottages/?cottages/5/     --> all direct to  /lake-district-cottages/cottages/5/

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?[^\ ]+
RewriteCond %{QUERY_STRING} ^/*([^=&]*[^=&/])/*(&+(.*))$
RewriteRule ^(.*[^/])/?$ /$1/%1/?%3 [N]
RewriteCond %{REQUEST_URI} !^/result
RewriteCond %{REQUEST_URI} !^/shop-result

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?[^\ ]+
RewriteCond %{QUERY_STRING} ^/*([^=&]*[^=&/])/*$
RewriteRule ^(.*[^/])/?$ /$1/%1/?%4 [L,R=301]
RewriteCond %{REQUEST_URI} !^/result
RewriteCond %{REQUEST_URI} !^/shop-result

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?[^\ ]+
RewriteCond %{QUERY_STRING} ^/*([^=&]*[^=&/])/*=/*([^&]*[^&/])/*(&+(.*))$
RewriteRule ^(.*[^/])/?$ /$1/%1/%2/?%4 [N]
RewriteCond %{REQUEST_URI} !^/result
RewriteCond %{REQUEST_URI} !^/shop-result

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?[^\ ]+
RewriteCond %{QUERY_STRING} ^/*([^=&]*[^=&/])/*=/*([^&]*[^&/])/*$
RewriteRule ^(.*[^/])/?$ /$1/%1/%2/? [L,R=301]
RewriteCond %{REQUEST_URI} !^/result
RewriteCond %{REQUEST_URI} !^/shop-result

# this stops you accessing pages with php extention eg
#/lake-district-cottages.php --> directs to /lake-district-cottages/ 
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^.#?\ ]+)\.php([#?][^\ ]*)?\ HTTP/

# this ignors the include folder and does not add trailing slash (so ajax file works)
RewriteCond %1 !^include/
RewriteRule ^([^.]+)\.php$ /$1 [R=301,L]

#this removes php extention
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

#this removes php extention and adds trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ $1.php

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

#these re-write urls  allowing  / to replace ? and =
RewriteRule ^lake-district-cottages/cottages/([0-9]+) lake-district-cottages.php?cottages=$1
RewriteRule ^lake-district-hotels/hotels/([0-9]+) lake-district-hotels.php?hotels=$1
RewriteRule ^lake-district-bed-and-breakfast/bed-and-breakfast/([0-9]+) lake-district-bed-and-breakfast.php?bed-and-breakfast=$1
RewriteRule ^lake-district-lodges/lodges/([0-9]+) lake-district-lodges.php?lodges=$1
RewriteRule ^lake-district-cottages-shop/lake-district-book-shop/([0-9]+) lake-district-cottages-shop.php?lake-district-book-shop=$1
RewriteRule ^lake-district-lodges/lodges/([0-9]+) lake-district-lodges.php?lodges=$1
RewriteRule ^result/([a-zA-Z0-9])/([0-9]+) result.php?$1=$2
RewriteRule ^shop-result/([a-zA-Z0-9])/([0-9]+) shop-result.php?$1=$2
By : AJFMEDIA


Answers

The condition pattern doesn't match your URLs that contain PATH_INFO, but simplifying it a bit to something like this should take care of that:

RewriteCond %{THE_REQUEST} ^[A-Z] \ /([^.?\ ] )\.php
RewriteCond %1 !^include/
RewriteRule ^([^.] )\.php(/. )?$ /$1%{PATH_INFO} [R=301,L]
By : Tim Stone


This video can help you solving your question :)
By: admin