This module provides a rule-based rewriting engine to rewrite requested URLs on the fly. Let’s see how to set it up and working in a few steps.
It comes bundled with Apache HTTP Server. To install Apache server on Linux:
apt-get install apache2
yum install apache2
then enable the mod (not enabled by default)
Now we are going to enable application specific settings on the apache server.
- Go to /etc/apache2/sites-available/
- Open default for editing.
- Replace AllowOverride None with AllowOverride All
Options Indexes FollowSymLinks MultiViews
allow from all
All left is to check if it’s working. Since we’re going to need PHP install it and restart apache.
apt-get install php5 libapache2-mod-php5
Enter the root directory of the web app you want to use mod_rewrite with.
echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
Open/Make a file .htaccess and add the following lines:
RewriteRule ^.*$ index.php
This rule will redirect everything that comes to your web app to index.php inside the same app, and print the full address.
A good mod_rewrite cheat sheet can be found here. (courtesy of AddedBytes)