15

NOV

How to make mod_rewrite work on wamp

by krike in tips & tricks

A simple trick to make mod rewrite work on your wamp server.

Author: krike

I'm an enthousiast web designer/developer who's trying to learn as much as possible and likes to share his knowledge with others.

I have been wondering for a long time now why mod_rewrite didn’t work on wamp and actually it’s quite easy even if I had to spend a lot of time searching.

In this quick tutorial I will show you how to make mod_rewrite work in wamp

First of all make sure the rewrite module is active on your wamp.

So right click on the wamp icon and go to apache->apache module and make sure rewrite module is checked

activate_rewrite_module

Now here is a small piece of my htaccess and of course it will only work on my live website, otherwise I wouldn’t be writting this article.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)/$ ./$1.php
RewriteRule ^tutorial/([0-9]+)$ /cmstut/view_tutorial.php?tutorial_id=$1 [QSA,L]
</IfModule>

Now let’s make this work on wamp

As you can seeĀ  RewriteBase is set to / but my website on my wamp server is actually in the folder cmstut and not the root of wamp, so I need to change it to RewriteBase /cmstut/

next thing is to change the rewrite url from

RewriteRule ^(.*)/$ ./$1.php
RewriteRule ^tutorial/([0-9]+)$ ./view_tutorial.php?tutorial_id=$1 [QSA,L]

to

RewriteRule ^(.*)/$ /cmstut/$1.php
RewriteRule ^tutorial/([0-9]+)$ /cmstut/view_tutorial.php?tutorial_id=$1 [QSA,L]

of course replace cmstut folder name with your folder unless your site is in the root of wamp.
In that case I don’t think you need to change anything to your .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cmstut/#RewriteCond %{REMOTE_HOST} !^81\.165\.9\.219
#RewriteRule .* http://www.iv-designs.org/maintenance/maintenance.html [R=302,L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-fb

Follow us on Twitter, or subscribe to our rss feed.

2 Comments

  1. Dennis Perremans on 29 Nov 2009

    Just open the httpd.conf file on Wamp, Mamp or Xamp,…
    On Xamp you can find it on /etc/httpd.conf

    Find the “LoadModule rewrite_module modules/mod_rewrite.so” line and delete the “#” symbol in front of it.
    # means that the line is a comment

    On Map you can find the file on /conf/apache/httpd.conf

  2. krike on 29 Nov 2009

    That’s another way of doing it, especially for XAMP which doesn’t have the same menu system as wamp or mamp.

Drop us a word