How to automatically change the URL for all php files in this directory

There is a URL www.мойсайт.ru/pages/start.php; you need to change the extension .php to .html and also hide the /pages/directory. As a result, the URL should look like this: www.мойсайт.ru/start.html and all this should happen automatically for all php files in this directory. What code should I write?

 1
Author: Kromster, 2012-06-29

2 answers

As far as I know, you can change the file extension from . php to . html, and then add the code to .htaccess:

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html .phtml

But just keep in mind that all files with the extensions .htm .html. phtml (even if they do not contain php code, but only consist of html) will be processed as . php, which may slightly increase the load on the server.

 2
Author: Sever, 2012-06-29 09:12:19

Initially, create a file .htaccess in your root directory of the site, and then fill in this code in this file.

This excerpt will remove the extension display.html for all html files. This code can be easily adapted for other extensions, such as php.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
**Заменить html вашими собственными расширениями. К примеру: php, htm, asp**
 2
Author: webkostya, 2019-06-04 09:24:23