To avoid having the ".php" extension in the URL, you can use URL rewriting. This is a technique that allows you to map a URL to a file on your server without having the file extension appear in the URL.
Here's an example of how you can set up URL rewriting using Apache server and the mod_rewrite module:
Enable the mod_rewrite module in your Apache server:
sudo a2enmod rewrite
In your .htaccess file, specify the rewrite rules:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/ [L]
In your index.php file, use the $_SERVER['REQUEST_URI'] to determine the path and route the request accordingly:
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
switch ($path) {
case '/home':
// Render the home page
break;
case '/about':
// Render the about page
break;
...
}
This will allow you to set a specific path to the file according to the work, without the .php extension appearing in the URL. For example, http://example.com/home would load the home page, while http://example.com/about would load the about page.