Skip to content

Instantly share code, notes, and snippets.

@travismillerweb
Created March 6, 2014 20:38
Show Gist options
  • Save travismillerweb/9399170 to your computer and use it in GitHub Desktop.
Save travismillerweb/9399170 to your computer and use it in GitHub Desktop.
Apache - Remove .php from File URL
## Remove .php from File URL
## Reference Link: http://stackoverflow.com/questions/15917258/remove-php-from-urls-with-htaccess
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment