How to check whether mod-rewite is enabled on Apache server
mod-rewite is a URL rewriting module provided by Apache. We use this module to rewite or beautify our site URLs.
Although all web hosting service providers have pre-installed this module but in some cases you must enable it yourself in order to use RewriteRules in htaccess.
In this post , I will show how you can know whether mod-rewite ( URL rewiting module ) is activated on your apache web server and how you to activate it yourself if its not already activated.
Keep on reading!!
How to know whether mod rewite is active ?
One of the simplest ways to check mod-rewrite is PHP’s function php_info() .
With php you can easily get informations about all installed/active modules on your server.
Checking mod-rewite by php
PHP’s php_info() function returns a list of all active modules on apache server. Create a file test.php in your web directory with the following code and save it.
Now open the file in your web browser. You will see a list of all available modules on your webserver. The test.php will show you contents something like the following:
All module that your server is using will be printed. Read the file from top to bottom , if you don’t see mod-rewite that means the module isn’t installed.
Check mod-rewite by htaccess
You can also check whether mod-rewite is enabled on your server by htaccess.
Create an htaccess file in your web root directory and put the following code
RewriteRule ^foo/?$ http://example.com [R]
Now visit : yoursite.com/foo . If mod-rewite is enabled Then the htaccess rule will redirect you to http://example.com else you will get an internal server error with 500 status code.
How to enable mod-rewite on Apache?
You can enable this module easily by editing your server.config file. Open your server configuration file and put the following line to enable the module :
This line tells server to read rewrite rules from htaccess file rather then reading server.config.
If your webhost doesn’t allow you to edit server.config file then contact your hosting service to enable it for you.
Hope this helps. Thanks for reading!