Installing Mod_Rewrite on Apache

Last Update : 21/03/2010 9:37pm
assets/Uploads/_resampled/SetWidth250-apachelogo.png

Mod_rewrite is used to change the URL using the commands rewriting engine (based on regex parser) is requested on the fly (directly). To use this module the Apache minimum version required is Apache 1.2 or latest version. You can install as a module mod_rewrite on your Apache webserver.

Before you install this module first checks whether the module is already installed by using phpinfo() if you are using php as a web programming. Loaded Modules section will appear modules that already installed, look for the words mod_rewrite, if exists you do not need to install the module, if not then prepared to install it.

Apache Handlers

The author uses Apache/2.2.12, PHP/5.2.10, Apache server bundle with Ubuntu Linux as operating system. To install this module looking for Apache httpd.conf file found in "/etc/apache2". Open the file with your preferred editor, notepad, gEdit, vim, nano, etc.. Find rows that contain word mod_rewrite. 

# LoadModule rewrite_module modules/mod_rewrite.so

Then remove the sign # in line to become:

LoadModule rewrite_module modules/mod_rewrite.so

Save the httpd.conf file and then restart your Apache, the mod_rewrite module is ready for use. To ensure re-check with the phpinfo().

To make the file is easy, open your editor and save as the name ".htaccess". 

If you are hosting to a provider usually we are not allowed to use the file type ".htaccess", then ask your provider to allow it. If you are using in the test localserver the configuration file is in httpd.conf, find the location of the directory where you placed the files of your web.

        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all # You must change
                Order allow,deny
                allow from all
        </Directory>

This section is to restrict the use of ".htaccess" on the server, for security settings are at "None" in this case to menggunakani mod_rewrite then turned into "all".

After all the preparation has been done so mod_rewrite is ready to use. Now open your .htaccess file and write the following code then save.

Options +FollowSymLinks 
RewriteEngine On 
RewriteRule google http://www.google.com/? [R,L]

Call your browser and type localhost/google or www.yourdomain.com/google, if the URL directly redirect to google.com means your mod_rewrite is running.

Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments