Monday, August 06, 2007

APACHE: Problem with mod_rewrite setup

One way to see if mod_rewrite is installed is to create a file called info.php with the following contents

 <?php echo phpinfo(); ?> 


Put the file in your server root and view it at http://localhost/info.php. Go to the apache section and look at Loaded Modules. If you see mod_rewrite listed there, you can start using the mod_rewrite commands. If not, you have to play with the apache config file: http.conf, add the following (a website told me to do this):

LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c


... and make sure the mod_rewrite.so file is in the right place. Then restart your web server. (suse linux: "rcapache2 restart", or windows: Control Panel->Administrative Tools->Services, right click on Apache and select restart)

PROBLEM:
Apache fails to restart.

In windows you can discover the reason using the Event Viewer (Control Panel->Administrative Tools->Services->Event Viewer). It gives the error for Apache:
Invalid command 'AddModule', perhaps mis-spelled or defined by a module not included in the server configuration

REASON:
AddModule for mod_rewrite is for apache 1.2 to 1.3x, but not apache2. I was running Apache2, so instead, the following worked for me in the apache config file:

LoadModule rewrite_module modules/mod_rewrite.so


Now restart apache, and check your http://localhost/info.php file and Voila! mod_rewrite is there, listed as a Loaded Module.

Now as for how to actually use mod_rewrite there are a lot of examples out there,
thats what google is for, right?

http://hypermail.linklord.com/new-httpd.old/2001/Jul/0863.html

No comments: