Testing mod_rewrite

If you face issues in getting rewrite rules of your website to work, first check if mod_rewrite is installed/enabled.
# httpd -l | grep rewrite

If mod_rewrite is installed on the server, you will get the following output :

  mod_rewrite.c

If it is not installed, then you will have to recompile apache with mod_rewrite enabled. In cPanel servers, you can do that using easyapache (/scripts/easyapache). Once installed then comes the testing part. To test mod_rewrite, simply add the following code to .htaccess file of your website:

RewriteEngine on
RewriteRule ^testpage.html http://google.com [R]

Once the .htaccess file has been updated, enter the following into your browser:
www.yoursite.com/testpage.html replace yoursite.com with your website name. If mod_rewrite is working fine, then the page will get redirected to Google.

That’s it.. 🙂

About Sarath

A Techie from Kochi, India with 8+ years of experience in Linux and Windows server administration. I learn new things almost everyday and I enjoy the fun of learning and sharing my knowledge.