Last active
August 3, 2017 07:58
-
-
Save xxjapp/fd914df0bef717d80e93e545cdde485f to your computer and use it in GitHub Desktop.
hide php extension in url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://php.net/manual/en/security.hiding.php | |
So far I haven't seen a working rewriter of /foo/bar into /foo/bar.php, so I created my own. It does work in top-level directory AND subdirectories and it doesn't need hardcoding the RewriteBase. | |
.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