Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Rewrite .php file without .php extension with .htaccess ULTIMATE SOLUTION

Options +MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# To externally redirect /dir/foo.php to /dir/foo/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s([^.]+).php [NC]
RewriteRule ^ %1 [R,L]

# To internally redirect /dir/foo/ to /dir/foo.php
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
#NOTE: the above will rewrite file eg. about.php to about/

#NOTE: rewrite to about/ to about or login/ to login, etc.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]
 
PREVIOUS NEXT
Tagged: #Rewrite #file #extension #ULTIMATE #SOLUTION
ADD COMMENT
Topic
Name
5+5 =