Php – Cannot load mod_rewrite Apache module

.htaccessapache-2.4httpd.confmod-rewritePHP

I am trying to use mod_rewrite module of Apache24 server, but I am not being able to load it. I know there have been many questions asked regarding this topic and I have gone through all of them but nothing seem to work. These are the steps that I have followed until now—

  1. CHANGED httpd.conf file made these changes:
    a. Uncommented LoadModule rewrite_module modules/mod_rewrite.so
    b. Changed AllowOverride None to AllowOverride All

  2. Restarted apache server

  3. Checked loaded modules using command prompt command httpd -M. I can see there that the mod_rewrite module has loaded. I am attaching the image below.

The screen shot of my command prompt

But after performing all these steps I can't see mod_rewrite as loaded module in phpinfo.

Screenshot of phpinfo file

As it can be seen in the above pic there is no mod_rewrite loaded module.
Also as a wild hack I even tried rewriting URLs using .htaccess file but this is not working. Apache seems to ignore .htaccess file although I have put that file inside my root directory.

 Note: I am running `PHP` as an apache module
 Using `WAMP` stack
 Using `localhost` as server

I need this module badly for URL rewriting purposes. Can you guys suggest some other way to load this module?

EDIT

I have tried to rewrite URL from virtual host as the answer suggests that the module is loaded and it does not depend neither on .htaccess nor on info.php.But stil it is not redirecting. I am adding the Virtual host setup below—

<VirtualHost *:80>
<Directory "/Apache24/htdocs">
Options FollowSymLinks 
AllowOverride All
DirectoryIndex index.html index.php
</Directory>
ServerName localhost
DocumentRoot "/Apache24/htdocs"
ErrorLog "/Apache24/logs/error.log"
CustomLog "/Apache24/logs/access.log" combined
<directory "/Apache24/htdocs">

    <IfModule rewrite_module>
            Options +FollowSymlinks
            RewriteEngine On
    </IfModule>

    <IfModule rewrite_module>
            RewriteRule   ^working.php   fun.html
    </IfModule>

</directory>
# Rewrite Rules #####################
RewriteEngine On
RewriteRule   ^working.php   fun.html
# end Rewrite Rules #################   
</VirtualHost>

The above code does not redirect it to working.php when I try to run fun.html. It simply says:

the requested URL /working.php was not found on this server.

Best Answer

  1. You don't need .htaccess or AllowOverride for mod_rewrite to work, don't use, since you are the admin of your server, since it will just complicate your life and cause unnecessary overhead to your server.
  2. Aside from Loading the module the only directive you need is:

    RewriteEngine on

Extra:

  1. Consider Redirect/RedirectMatch instead (from mod_alias) for simple redirections, if that's all you need.
  2. Consider defining your redirects/rewrites in virtualhost context to avoid future nightmares and loss of hair in the near future.
Related Topic