Apache – how to remove php extension from url

Remove php extension from a specific url

To remove php extension from a url (e.g. /foo/bar.php) the following Apache rewrite rule can be used:

RewriteRule ^/foo/bar  /foo/bar.php [L]

Remove php extension from a directory

The following RewriteRule can be used to remove php extension from a directory. We are assuming file name (before .php extension) contains only dash and alphanumeric characters.

RewriteRule ^/foo/([-\w]+)  /foo/$1.php [L]
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments