To remove .php (for example) file extensions put the following in a .htaccess file in your document root
No trailing slash:
- Code: Select all
Options +FollowSymLinks
RewriteEngine On
# Redirect to remove /index.php files.
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.php(\?.*)?\ [NC]
RewriteRule ^(.+/)?index\.php$ /%1 [NC,R=301,L]
# Redirect to remove .php
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{SCRIPT_FILENAME} -f
RewriteCond %{REQUEST_URI} ^(/.+)\.php$
RewriteRule ^(.+)\.php$ %1 [R=301,L]
# Rewrite to add .php back.
RewriteCond %{REQUEST_URI} ^(/.+)$
RewriteCond %{SCRIPT_FILENAME}.php -f
RewriteRule ^(.*[^/])$ %1.php [QSA,L]
With a trailing slash:
- Code: Select all
Options +FollowSymLinks
RewriteEngine On
# Redirect to remove /index.php files.
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.php(\?.*)?\ [NC]
RewriteRule ^(.+/)?index\.php$ /%1 [NC,R=301,L]
# Redirect to remove .php
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{SCRIPT_FILENAME} -f
RewriteCond %{REQUEST_URI} ^(/.+)\.php$
RewriteRule ^(.+)\.php$ %1/ [R=301,L]
# Rewrite to add .php back.
RewriteCond %{REQUEST_URI} ^(/.+)/$
RewriteCond %{DOCUMENT_ROOT}%1.php -f
RewriteRule ^.+/$ %1.php [QSA,L]
To remove a different file extension replace all references to php with the file extension you want to remove.