Assuming you want to show the "pretty" URL (example.com/cool
) but still get the data from the original request (example.com/cool.php
), you may try this in the .htaccess file at root directory:
Updated to work with php files at any directory:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Get the URI-path directly from THE_REQUEST variable
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\s/(.*)\.php [NC]
# Strip the extension and redirect permanently
RewriteRule .* /%2 [R=301,L,NC]
# Now the browser's address bar shows: http://example.com/cool
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.php [NC]
# Map internally to the original resource
RewriteRule ^(.*)/? /$1.php [L,NC]
# Maps silently to: http://example.com/cool.php