skip to Main Content

I tried a lot of code to remove .php from url
for example – ht.abuena.net/presto.php -> ht.abuena.net/presto
and vice versa – internally

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

nothing works – the url stays unchanged
page is reloading by right clicking on the button Reload and choosing – Empty Cache and Hard Reload – so I hope the cache is cleared

live example here – here

2

Answers


  1. With your shown samples, please try following htaccess rules file.

    Please make sure to clear your browser cache before testing your URLs.

    RewriteEngine ON
    RewriteBase /
    
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    ##using THE_REQUEST variable for condition check.
    RewriteCond %{THE_REQUEST} s/([^.]*).php/?s [NC]
    ##Performing external redirect here.
    RewriteRule ^  %1? [R=301,L]
    
    ##Performing rewrite for non-existing pages.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT}/$1.php -f
    RewriteRule ^(.*)/?$ /$1.php [QSA,L]
    
    Login or Signup to reply.
  2. In my case if the project is core PHP one, I use the below lines in .htaccess file:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php [NC,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search