Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To remove both ".php" and trailing slashes from URLs using .htaccess, you can use the following code:

# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# remove .php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)/?$ $1.php [L]

This code will first remove any trailing slashes from the URL, and then it will remove the ".php" extension from the end of the URL. Both of these changes will be applied using a 301 redirect, which is a permanent redirect that tells search engines that the URL has moved permanently.