neophyte
neophyte

Reputation: 6626

Cannot load mod_rewrite Apache module

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

  1. Restarted apache server

  2. 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. enter image description here

But after performing all these steps I can't see mod_rewrite as loaded module in phpinfo. enter image description here 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?

I am cracking my head for the past two days. Do you think a re-installation is needed or has it got something to do with path dependencies. Any suggestion will be appreciated.

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.. Thanks in advance!

Upvotes: 0

Views: 2569

Answers (1)

Daniel Ferradal
Daniel Ferradal

Reputation: 2890

If apachectl -M or httpd -M says the module is loaded, it is loaded. phpinfo is an external thing ran by a php script, why should you trust it over httpd own software?

If you really need to use mod_rewrite, just make sure to add RewriteEngine on before your other rewrite directives.

Note: I would really make sure I need mod_rewrite knowing what I have to configure next, in many cases it is not necessary and overused.

Very important: To configure your server, if it is your server you do not need .htaccess, and mod_rewrite does not depend on it either

Upvotes: 1

Related Questions