Today we will discuss about mod_rewrite. First we will know about mod_rewrite.

Mod_rewrite is an Apache Web server module installed on all of our Linux servers by default; it does not have to be installed or enabled. Our Linux hosting accounts support most mod_rewrite functions.

mod_rewrite provides a flexible and powerful way to manipulate URLs using an unlimited number of rules. Each rule can have an unlimited number of attached rule conditions, to allow you to rewrite URL based on server variables, environment variables, HTTP headers, or time stamps.

mod_rewrite operates on the full URL path, including the path-info section. A rewrite rule can be invoked in httpd.conf or in .htaccess. The path generated by a rewrite rule can include a query string, or can lead to internal sub-processing, external request redirection, or internal proxy throughput.

Open your website root directory, create a php file rewrite.php.

Now enter following code in rewrite.php page

<?php echo "Mod_rewrite is activated!"; ?>

Now open your website/rewrite.php in your browser. In attached image we created a directory mod and under this directory create php page rewrite.php.

 

Screenshot_42

 

Now you need to create .htaccess page in your web directory and put below code:

RewriteEngine On
RewriteRule ^.*$ rewrite.php

 

After that you will interface look like.

 

Screenshot_43

 

Don’t forget to drop your feedback in the comments section below if you found this article helpful.