2

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]
3
  • What you should do is to redirect user from /file.php to /file/. Commented Mar 19, 2013 at 16:49
  • a redirect issues an infinite loop :/ Commented Mar 19, 2013 at 17:04
  • When I think about it, I had the same problem. I'm sure I just gave up back then. So good luck :) Commented Mar 19, 2013 at 17:05

1 Answer 1

3

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]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.