How to enable mod_rewrite in Apache ?

Discussion in 'Apache' started by mihai11, Nov 28, 2006.

  1. #1
    Hi all,



    I installed Apache as part of WAMP package (it comes with Apache 2.0.59). In order to enable mod_rewrite in Apache I did the following:

    1. Uncomment the following line in httpd.conf file:

    LoadModule rewrite_module modules/mod_rewrite.so

    2. Put a .htaccess file in the root directory:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ super.html

    3. Restart Apache

    If my understanding is correct, when I type

    www.somesite.com/super.html

    I should be redirected to

    www.somesite.com/index.php

    but this doesn't happen. Most probably my mod_rewrite engine is not enabled ? How can I test if it is truly enabled ?



    Regards,
    Razvan
     
    mihai11, Nov 28, 2006 IP
  2. disgust

    disgust Guest

    Messages:
    2,417
    Likes Received:
    133
    Best Answers:
    0
    Trophy Points:
    0
    #2
    do other htaccess commands work? it's possible mod rerewrite is working but htaccess is off :)
     
    disgust, Nov 28, 2006 IP
  3. mihai11

    mihai11 Peon

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I don't think that it is disabled, because I have this line in my httpd.conf file:

    Anyway, just to make sure: what other commands can I put there ? I mean just to test that .htaccess is working. (sorry, I am a beginner with this stuff)


    Regards,
    Razvan
     
    mihai11, Nov 28, 2006 IP
  4. mihai11

    mihai11 Peon

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I found the issue myself. In order for the .htaccess file to work you must give the directive "AllowOverride" for the respective folder:

    Since I am using virtual hosts my httpd.conf file now looks like this:

    <VirtualHost 127.0.0.1:80>
    	ServerName [url]www.xml-forums.net[/url]
    	ServerAlias xml-forums.net
    	DocumentRoot D:/www-xml-forums.net
    
    	LogLevel warn
    	ServerSignature On
    
    	<Directory "D:/www-xml-forums.net">
    		Options Indexes FollowSymLinks
    		[COLOR="Red"][B]AllowOverride All[/B][/COLOR]
    		Order allow,deny
    		Allow from all
    	</Directory>
    
    </VirtualHost>
    Code (markup):
     
    mihai11, Nov 28, 2006 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #5
    Use

    RewriteEngine On
    RewriteBase /
    RewriteRule ^super\.php$ index.html [L]

    IF index.html is the original URL, with super.php being the fake URL. Then super.php should show the same thing as index.html. It doesn't redirect to the original URL.
     
    Nintendo, Nov 29, 2006 IP
    sachin410 likes this.
  6. mihai11

    mihai11 Peon

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I understand that. The problem was the command "AllowOverride All" that has to be applied for the folder where you want to use .htaccess.

    Is this a security risk ? Is there a more restrictive settings that you people use instead of "All" ?
     
    mihai11, Nov 29, 2006 IP