Skip to content

Instantly share code, notes, and snippets.

@Cristy94
Created July 7, 2021 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cristy94/f877f0e00f0569666cb71348b6591a25 to your computer and use it in GitHub Desktop.
Save Cristy94/f877f0e00f0569666cb71348b6591a25 to your computer and use it in GitHub Desktop.
# Remove .php extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ (.*)\.php [NC]
RewriteRule ^ %1 [R=301,NE,L]
# Check whether the file exists then set it back internally
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^.*$ $0.php [L,NE]
## Notes:
## [NE] - NotEscape flag is needed so the redirect works with UTF8 URLs (eg. Chinese character)
## The first block removes the .php extension, the second one serves the correct file when the extension is missing
## ^[A-Z]{3,}\ - Skips the POST or GET method from the HTTP request (THE_REQUEST)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment