There are different ways of achieving the same results, but this will give you a guide.
First activate mod_rewrite uncommenting this line in you httpd.conf or apache2.conf file:
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
Change AllowOverride from none to All to your www directory
<Directory />
AllowOverride All
Require all denied
</Directory>
Restart apache:
sudo apachectl restart
or
sudo service apache2 restart
In your www folder, create an .htaccess file and add this:
# | SEO URL
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php
Then in your index.php file:
<?php
$url_params=get_url_params();
// then access your url_params
if (isset($url_params[1]))
{
switch ($url_params[1])
{
case 'login':
echo "<h1>Login</h2>";
break;
case 'contact':
echo "<h1>Cantact</h2>";
break;
default:
echo "<h1>Home</h2>";
break;
}
}
function get_url_params($site_url='')
{
$base_url=explode("/", $site_url);
$request = $_SERVER['REQUEST_URI'];
$url_params = explode("/", $request);
$delete_extensions=array('.html','.htm');
$data[]=array();
foreach ($base_url as $b)
{
unset( $url_params[array_search( "$b", $url_params )] );
}
foreach ($url_params as $u)
{
foreach ($delete_extensions as $e){
$u=str_replace($e, "", $u);
}
$data[]=$u;
}
return $data;
}
?>