1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to set mod_rewrite log in .htaccess?

Discussion in 'Apache' started by ForumJoiner, Oct 18, 2007.

  1. #1
    I have a shared web hosting account. I want to be able to access the mod_rewrite log, but I don't have access to httpd.conf file. Can I do it using .htaccess? (Apache is version 1.3, under Linux)

    How else to debug a .htaccess that doesn't do redirects I expected?
    Is any way to find out what is the result of the Rewrite rule?
     
    ForumJoiner, Oct 18, 2007 IP
  2. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Rewrite Logs are quite difficult to read, especially if you are doing this on a live server and have multiple concurrent requests.

    It generally easier to debug rewrite rules in other ways. The first technique I would suggest is adding [R] after the rule. This will turn it into a redirect (302 response code) which will show exactly what final URL is being requested in your browser's address bar.

    The most common problem is that the rule you think should match a URL is not matching but another one below it in the file is matching. Another, slightly less common problem is when a rule matches different parts of the URL than what you thought it would match. (.*) is particularly dangerous for this.

    A technique to determine which rule is matching is to create a rule:
    RewriteRule .* http://google.com [R]
    Code (markup):
    which you place as the first line in your .htaccess file. After each request of the page you want, you move it down one line until it no longer matches (i.e you are no longer redirected to google.com) The rewrite rule above the google rule is the one that matches.
     
    Ladadadada, Oct 18, 2007 IP
  3. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #3
    How about the lines below? I use the [R], but the address bar doesn't change and Apache answers (after about 2 minutes - I believes it enters in a loop) with:
    "Internal Server Error
    The server encountered an internal error or misconfiguration and was unable to complete your request.
    Apache/1.3.33 Server"

    I try to access http://mydomain/test-1


    My .htaccess looks as following:
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ main.php?page=$1 [R]
     
    ForumJoiner, Oct 18, 2007 IP
  4. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Add this in instead:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^main.php
    RewriteRule ^(.*)$ main.php?page=$1 [R]
     
    Ladadadada, Oct 19, 2007 IP