Skip to content

Instantly share code, notes, and snippets.

@JulaineScott
Created April 7, 2020 05:14
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 JulaineScott/f19ceebd72ef65eec473adab5c914866 to your computer and use it in GitHub Desktop.
Save JulaineScott/f19ceebd72ef65eec473adab5c914866 to your computer and use it in GitHub Desktop.
Change php files to slugs
#1)externally redirect "/file.php" to "/file"
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
#2)Internally map "/file" back to "/file.php"
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,L]
@JulaineScott
Copy link
Author

JulaineScott commented Sep 28, 2021

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.) $1.php [L]
#if no file, send to 404
RewriteCond %{THE_REQUEST} "^[^ ]
.?.php[? ].$" RewriteRule .* - [L,R=404]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment