-2

I want to remove .php extension from my url, so I edited .htaccess to add this code

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

And the code works fine but only when I intentionally remove .php from the URL and I want it to be an automatic process so is it possible?

1
  • What do you want to happen exactly if user heads to http://example.com/foo.php? An external redirection? A 404 status code? Commented Jul 3, 2018 at 9:50

2 Answers 2

1

It worked for me:

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
Sign up to request clarification or add additional context in comments.

4 Comments

'forward /dir/foo to /dir/foo.php' that's not what he asked.
@Jitrenka it will forward the request internaly.
Worked for me too, thank you!
@Nuha If it helped you. Please upvote & accept the answer for others.
-1

Are you redirecting to '*.php' in your code? It will of course, append the .php. Remove it and it won't add the extension.

1 Comment

Thank you! it worked when I did this and added the code from Rana Ghosh

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.