Sangwal’s Weblog

Just another WordPress.com weblog

mod_rewrite loaded but not working

with 4 comments

There are lot many tutorials on the Net about mod_rewrite module of Apache web server. You follow those tutorials and get nowhere (OK, at least I couldn’t for the most of time until I found http://ubuntuforums.org/showthread.php?t=645282).

This post particularly deals with Apache 2.0 series. I am afraid if this material is applicable to Apache1.3 series of server, however, you can try yourself if it works for you.

Make sure that mod_rewrite is loaded. This can be done by checking PHP settings. Put <?php phpinfo(); ?> this code into a PHP file and browse this using a browser. It will display PHP info along with loaded modules in Apache. Search this page for string “mod_rewrite”. If you can find this, it means that the module is loaded and you can skip the rest of this paragraph. Still here, most likely you have not mod_rewrite loaded, yes? Under Ubuntu Linux (in other distros also, I think) you can load this module using sudo a2enmod rewrite command in the terminal window.

For Linux

The httpd.conf file is not used in Apache2; the new configuration file is apache2.conf. On my installation, the httpd.conf was just empty (zero byte file size). All installation wide configuration of Apache2 can be done through apache2.conf file making httpd.conf redundant.
Many of the tutorials I came across point out that we have to change “AllowOverride None” to “AllowOverride All”, but unfortunately failed to pin point where exactly this setting is to be changed. Of course, the problem I had was with this setting only. (I am next to sure that you also have problem with this setting only.) Locate the file: /etc/apache2/sites-enabled/000-default. Search for the section

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/$ /apache2-default/
</Directory>

Now change “AllowOverride None” to “AllowOverride All”. Force restart the server using sudo /etc/init.d/apache2 force-restart and you are done.

For Windows

The Apache2 configuration file under windows is httpd.conf. Look for the line

#LoadModule rewrite_module modules/mod_rewrite.so

in the httpd.conf file. Remove the leading # comment sign to enable the server to load the module. Next, search for

<Directory "${path}/www">
:
AllowOverride None
:
</Directory>

section. Here you will find AllowOverride None line. Change it to AllowOverride All so that the setting in .htaccess file can be used by the server (otherwise, the server doesn’t process whatever is there in .htaccess file).

Of course you’ll need to restart the server for the things to work. I hope this will be helpful.

Written by sangwal

March 29, 2008 at 2:12 am

4 Responses

Subscribe to comments with RSS.

  1. Wow. Finally my problem solved. I spent around 2-3 hrs finding the solution on Google with out any luck. Only my frustration grew. Thanks a lot for posting the solution.

    Ram

    April 27, 2008 at 7:58 pm

  2. My pleasure! :)

    sangwal

    May 21, 2008 at 1:34 am

  3. Thank you thank you thank you man :-)

    rich

    July 12, 2009 at 10:51 am

    • Glad to know that it helped you :)

      sangwal

      July 15, 2009 at 5:34 pm


Leave a Reply