skip to Main Content

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?

2

Answers


  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.

    Login or Signup to reply.
  2. 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]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search