Last active
September 11, 2017 17:06
-
-
Save dvlden/facc2cf9eadc931557c4 to your computer and use it in GitHub Desktop.
Pretty URL's are always nice and great in many cases. This is how you rewrite your URL's to remove / strip off php extension
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
<IfModule mod_rewrite.c> | |
# remove trailing slash | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s] | |
RewriteRule ^(.+?)/$ /$1 [R=301,L] | |
# To externally redirect /dir/file.php to /dir/file | |
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC] | |
RewriteRule ^ /%1 [R=301,L,NE] | |
# To internally forward /dir/file to /dir/file.php | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{DOCUMENT_ROOT}/$1.php -f | |
RewriteRule ^(.+?)/?$ /$1.php [L] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment