Skip to content

Instantly share code, notes, and snippets.

@jquery404
Created November 1, 2018 10:26
Show Gist options
  • Save jquery404/5e6d794309b28a0766aa81e5f60e38d5 to your computer and use it in GitHub Desktop.
Save jquery404/5e6d794309b28a0766aa81e5f60e38d5 to your computer and use it in GitHub Desktop.
Remove .php from .htaccess
RewriteEngine on
# Rewrite /foo/bar to /foo/bar.php
RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]
# Return 404 if original request is /foo/bar.php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteRule .* - [L,R=404]
# NOTE! FOR APACHE ON WINDOWS: Add [NC] to RewriteCond like this:
# RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$" [NC]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment