In order to hide the .php and .html extensions from the file in the link, we need to make settings for the web server, we will consider the most popular options.
1. For the Apache web server, we will use the .htaccess file, which must be placed in the root directory of our site:
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]
RewriteRule ^([^.]+)$ $1.html [NC,L]
2. For the Nginx / PHP-FPM web server, we will use the host configuration file.
/etc/nginx/sites-enabled/site_com.conf
location / {
if (!-e $request_filename){
rewrite ^/([^.]+)$ /$1.php break;
}
rewrite ^/([^.]+)$ /$1.html break;
}
3. For Plesk 18 control panel, in case of htaccess use option 1, it is suitable for both hosting and server configuration. If using nginx / php-fpm, write the following directives:
Menu -> Apache and nginx settings
rewrite ^/?(.).php$ /$1 redirect;
rewrite ^/?(.).html$ /$1 redirect;
if (!-e $request_filename){
rewrite ^/([^.]+)$ /$1.php break;
}
if (!-e $request_filename){
rewrite ^/([^.]+)$ /$1.html break;
}