The mod_rewrite module uses a rule-based rewriting engine, based on a PCRE regular-expression parser, to rewrite requested URLs on the fly. By default, mod_rewrite maps a URL to a filesystem path. However, it can also be used to redirect one URL to another URL, or to invoke an internal proxy fetch.
Step 1 - Activate the mod_rewrite module using this command.
Step 2 - Now Restart the Apache service.
Step 3 - Now we need to make some changes on Apache configuration file. Here I use "000-default.conf" configuration file and search for “DocumentRoot /var/www/html” and add the following lines.
vi /etc/apache2/sites-available/000-default.conf
<Directory "/var/www/html">
AllowOverride All
</Directory>
Step 4 - Now again restart the Apache service and check the status on "phpinfo.php".
Step 5 - Here I have created a small example of mod-rewrite, put ".htaccess" file in webserver document root for testing.
That's it...