Please clear your browser cache and then put the following code at main root .htaccess
file :
DirectorySlash Off
RewriteEngine on
RewriteCond %{THE_REQUEST} s/+example [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*) /$1.php [R=302,L]
The code above will stop directoryslash
and make it off
so no file without slash goes to be directory as default and then check if example
exists in QUERY_STRING
and the trick comes here in this line RewriteCond %{REQUEST_FILENAME}.php -f
,it will check if adding .php
to this string , is that really file in directory or not ? and already we have example.php
in root so , it will go to last line to redirect any string that passed the rules above to itself.php
and that what you want exactly.
The above code will catch any example
in only root
directory with example
only but if wanna inherit other sub-folders or apply this rule to entire site so , whenever there is string without extension the priority will be for the file , put the following code at your main root .htaccess
file :
DirectorySlash Off
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*) /$1.php [R=302,L]
After testing this code , if it is Ok , change 302
to 301
to be permanent redirection
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…