there is code .htaccess

 RewriteEngine On RewriteRule ^(\w+)$ $1.php [NC] 

It allows you to access the pages without appending the .php file extension.

we also need a line that will hide the .php extension from the url if the user enters example.com/about.php there are also many links that lead to example.com/about.php , the link is not an option, therefore the line that will hide the extension in url if there is one.

  • I usually redirect all requests to index.php, and that, in turn, creates a router and loads the necessary controllers. - ilyaplot

1 answer 1

The problem is that .htaccess cannot change the url. You can only make a redirect from pages with the .php extension to pages without .php

  • This code removes the .php extension from each page, only it conflicts with the header function, so I'm looking for an analogue of RewriteCond% {REQUEST_FILENAME}! -f RewriteCond% {REQUEST_FILENAME}! -d RewriteCond% {REQUEST_FILENAME} .php -f RewriteRule ^. * $ $ 0.php [L, QSA] RewriteCond% {THE_REQUEST} ([^ \ s] *) \. Php (\? [^ \ S] *)? RewriteRule (. *)% 1 [R = 301, L] - hovdev