How to check whether mod_rewrite is enable on server?

Usually cpanel(WHM) compiles mod_rewrite by default. You can check with this:


root@server [~]# httpd -l|grep rewrite

So you must just activate it in your ‘.htaccess’ using:


RewriteEngine On

To check if mod_rewrite module is enabaled, create a new php file in your root folder of your WAMP server. Enter the following

phpinfo();

Access your created file from your browser.

Ctrl+F to open a search. Search for ‘mod_rewrite’. If it is enabled you see it as ‘Loaded Modules’

If not, open httpd.conf (Apache Config file) and look for the following line.


#LoadModule rewrite_module modules/mod_rewrite.so

remove the pound (‘#’) sign at the start and save the this file.

Restart your apache server.

Access the same php file in your browser.

search for ‘mod_rewrite’ again. You should be able to find it now.

For Plesk Servers

Log into your server via ssh as root.

Mod Rewrite is enabled by default on plesk servers. You can verify this with the following command:

 
# apachectl -M | grep rewrite

modify the vhost.conf file at /var/www/vhosts/example.com/conf/vhost.conf

 
# replace "AllowOverride None" with "AllowOverride all".

restart apache with the following command:


service httpd restart
 

Create a .htaccess containing the following and upload it to the root of your site:

 
RewriteEngine On
RewriteRule ^google.html$ http://www.google.com/ [R=301]

Going to http://www.yoursite.com/google.html should redirect you to Google.com if you have mod rewrite enabled and your syntax is correct.

For more information on Mod rewrite see the following links.

http://httpd.apache.org/docs/current/mod/mod_rewrite.html
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

Leave a Comment