Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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