Tuesday 2 July 2013

Testing mod_rewrite

Posted by Sarath On Tuesday, July 02, 2013 No comments
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.. :)

0 comments: