htaccess not working

Discussion in 'Apache' started by departedM, May 20, 2010.

  1. #1
    Hello,
    I have this code on my htaccess file
    
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^([^/]*)/([^/]*)\.html$ /activity.php?c_id=$1&a_id=$2 [L]
    Code (markup):
    it does not work nor shows any error, I think mod_rewrite is not working. How can I check mod_rewrite is working or not.

    I have loaded the module in httpd.conf file.

    I have wamp installed in windows 7 .

    any help ?
    Thanks
     
    departedM, May 20, 2010 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    In the <virtualhost> container of the site, add the following two directives and then restart Apache.
    You'll need to add your own log file path for the first directive, you can just enter a path to say "log.txt" on your desktop.

    RewriteLog "C:\logs\rewrite.log"
    RewriteLogLevel 9
    Code (markup):
    After you restart Apache, look at a page that you think would trigger mod_rewrite, and then look at the contents of that RewriteLog log file. If there's anything in the file, mod_rewrite is definitely up and running. If it didn't work and there is stuff in that log file, post the contents of that log file after taking out anything that looks like an IP address or personal information. Don't remove file paths, but feel free to swap out something like "joe" with "username" if it makes you feel better.
     
    joebert, May 22, 2010 IP
  3. departedM

    departedM Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Sorry to bother you but I could not understand one thing, what do you mean by <virtualhost> container. In my httpd.conf file i added
    <virtualhost>
    RewriteLog "C:\logs\rewrite.log"
    RewriteLogLevel 9
    </virtualhost>

    after that WAMP does not start, it shows 2 of 3 services running.

    And when I add this code
    RewriteLog "C:\logs\rewrite.log"
    RewriteLogLevel 9

    in my htaccess file I get internal server error.

    Can you help me out,
    Thanks
     
    departedM, May 22, 2010 IP
  4. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #4
    You're not going to add a virtualhost, you're looking for the existing virtualhost for your current site and you're going to add those directives to the existing virtualhost.

    Look through the config files for your apache configuration, somewhere in there you should find an existing <virtualhost> container for the website. It should look something like this, but it will include a bunch of details specific to your site.

    <VirtualHost *:80>
    	ServerAdmin webmaster@localhost
    	DocumentRoot "C:\www\"
    Code (markup):
     
    joebert, May 23, 2010 IP
  5. departedM

    departedM Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    There is no VirtualHost inside my httpd.conf file evertthing is separate like this


    ServerRoot "d:/wamp/apache2"
    Listen 80
    ServerAdmin webmaster@localhost
    ServerName localhost:80
    DocumentRoot "D:/wamp/www"
     
    departedM, May 23, 2010 IP
  6. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #6
    Alright, go ahead and place the following two lines after your DocumentRoot directive.

    RewriteLog "D:/wamp/www/rewrites.log"
    RewriteLogLevel 9
    Code (markup):
    Then restart Apache, navigate to an address that should trigger your RewriteRule, then look at "D:/wamp/www/rewrites.log" in notepad. Try not to access more than one URL between the time you restart Apache and look at that file.
     
    joebert, May 23, 2010 IP
  7. departedM

    departedM Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Ok, I have posted only 4-5 lines, I don't understand this but looks like it is working
    127.0.0.1 - - [23/May/2010:13:57:16 +052700] [localhost/sid#7f1f90][rid#8d3d50/initial] (3) [perdir D:/wamp/www/mycomfort/] strip per-dir prefix: D:/wamp/www/mycomfort/activity.php -> activity.php
    127.0.0.1 - - [23/May/2010:13:57:16 +052700] [localhost/sid#7f1f90][rid#8d3d50/initial] (3) [perdir D:/wamp/www/mycomfort/] applying pattern '^([^/]*)/([^/]*)\.html$' to uri 'activity.php'
    127.0.0.1 - - [23/May/2010:13:57:16 +052700] [localhost/sid#7f1f90][rid#8d3d50/initial] (1) [perdir D:/wamp/www/mycomfort/] pass through D:/wamp/www/mycomfort/activity.php
    127.0.0.1 - - [23/May/2010:13:57:16 +052700] [localhost/sid#7f1f90][rid#8d5d58/initial] (3) [perdir D:/wamp/www/mycomfort/] strip per-dir prefix: D:/wamp/www/mycomfort/css/main.css -> css/main.css
    127.0.0.1 - - [23/May/2010:13:57:16 +052700] [localhost/sid#7f1f90][rid#8d5d58/initial] (3) [perdir D:/wamp/www/mycomfort/] applying pattern '^([^/]*)/([^/]*)\.html$' to uri
    Code (markup):
    Any thoughts

    Thanks for the reply
     
    departedM, May 23, 2010 IP
  8. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #8
    mod_rewrite is definitely working and your pattern is being considered when a request is made. When you're not testing mod_rewrite, you'll need to stop Apache, comment out those directives by putting a # symbol in front of them, and then start Apache again. if you don't do this the log file it generates can get really big really fast.

    Looking at the part you posted, it looks like you're trying to access activity.php in your browser. What was the URL you tested it with ?
     
    joebert, May 23, 2010 IP