0

This is my .htaccess file:

RewriteEngine On
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

When the user goes to http://local/home, it works fine, but if user goes to http://local/home.php, the .php stays there, it doesn't redirect to the page without the .php, so don't mark this as duplicate as I have researched it.

1 Answer 1

1

You don't have any rule that redirects a request to a php extension to redirect without it. That's why it stays there. Just because you've added a rule to internally rewrite a request that is missing the php extension doesn't mean it magically happens in the other direction. At the top of your rules you need to match against the actual request and redirect the browser when it requests a php file:

RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /(.+)\.php(\?|\ )
RewriteRule ^ /%2 [L,R=301]

More:

Just a matter of recognizing that a rule only does the one thing that its asked to do, match a pattern against the URI, and rewrite/redirect to the target.

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.