Remove “.php” extension from URL

In categories: Apache published on 16.08.2010 by Dejan Jacimovic

In order to have nice URLs you could use various techniques. But in case you have a really simple website with pages written in PHP, and URLs pointing to those PHP files like, you could set nice URLs using .htaccess only. Using following snippet will let you have URLs like, and still open your file.

Just use following snippet in order to remove “.php” extension from URL.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)/$ $1.php
  • Was this helpful?
  • Yes   No