Activate mod_rewrite module on Apache2.2 Windows installment.

Activate mod_rewrite module on Apache2.2 Windows installment.

I decided to take a look at highly glorified cms called snews and test it locally on my Apache2.2 server but struggled to enable mod_rewrite module in order to get my urls rewritten.

As you know mod_rewrite is used for rewriting URLs at the server level. The best example would WordPress permalinks, where you decide how url of your blog look like. By default it would be yourblog.com/?p=123 but with a help of mod_rewrite you get something like this: yourblog.com/post-about-this

How to check if mod_rewrite works on your Apache server?

I noticed that opening phpinfo page (create file phpinfo.php with this source code:

<?php phpinfo(); ?>

and load via localhost) isn’t enough to determine whether mod_rewrite module works. You should test this by practicaly trying to change url.

  • At first create .htaccess file with the code:
    RewriteEngine on
    RewriteRule ^first.html$ second.html
  • Create 2 html files named first.html and second.html and write 1 or 2, or first and second in them so that you could easily distinguish that in first.html a word “first” is written. Put those 2 files in the same folder where you put .htaccess file.
  • Load first.html via localhost. Your mod_rewrite works if you see first.html in the address bar but word “second” displayed in the page. Otherwise you need to enable mod_rewrite module.

Enable mod_rewrite module

  • Open httpd.conf file (locate it in start->apache program menu or go to apache installation directory and conf folder) and search (use ctrl+f) for #LoadModule rewrite_module string. Uncomment this line, i.e.
    line #LoadModule rewrite_module modules/mod_rewrite.so
    becomes LoadModule rewrite_module modules/mod_rewrite.so

  • Find and uncomment Options Indexes FollowSymLinks line
  • Change AllowOverride None to AllowOverride All

  • Restart Apache server and check again if mod_rewrite works

, , ,

Comments are closed.