Reputation: 616
i know there are many questions like "How do i remove the .php extension, so that /test/ will be /test.php" but if the user directly goes to test.php it doesnt replace the extension. So I want to replace the .php it should be /. here is the part of the .htacces I'm using:
RewriteEngine on
RewriteRule stuff\.php /other_stuff/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
Upvotes: 2
Views: 1147
Reputation: 143856
You need to do the check against the actual request instead of the URI (which gets rewritten by other rules). The %{THE_REQUEST}
variable doesn't change in the course of the rewrite engine. Try adding these rules right below the RewriteEngine
directive:
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /([^/]+)\.php(\?|\ |$)
RewriteRule ^ /%2/ [L,R=301]
Upvotes: 3