10

I have complicated RewriteCond and RewriteRule in one machine. And according to these rules, some of the requests will be redirected to another machine.

So is there any Apache log that shows clearly how the redirection takes place? Because the redirection is happening in the ways that I don't anticipate.

Rahul
  • 67
  • 1
  • 12
Graviton
  • 2,865
  • 12
  • 42
  • 64

3 Answers3

10

For the uninitiated, this is how you should write your *.conf file:

  NameVirtualHost *:80
  <VirtualHost *:80 >
    ServerName gw.myserver.net
    DocumentRoot "C:\Program Files\MyCompany\myserver\Web"
    DirectoryIndex index.html index.php
    RewriteLog "logs\rewritelog.txt"
    RewriteLogLevel 3
    <Directory  "C:\Program Files\ MyCompany\ myserver\Web">
       AddDefaultCharset UTF-8
       Order Deny,Allow
       Allow from all

       RewriteEngine on
       RewriteBase /
       RewriteCond %{HTTP_HOST}   ^gw\. myserver\.net$
       RewriteRule !^(login|index.php)  http://pmmenu. myserver\.net%{REQUEST_URI}$1 [L,R=301]
       # we check if the .html version is here (caching)
       RewriteRule ^$ index.html [QSA]
       RewriteRule ^([^.]+)$ $1.html [QSA]
       RewriteCond %{REQUEST_FILENAME} !-f

       # no, so we redirect to our front web controller
       RewriteRule ^(.*)$ index.php [QSA,L]
    </Directory>
  </VirtualHost>
Graviton
  • 2,865
  • 12
  • 42
  • 64
  • 2
    Good answer - uninitiated, please keep in mind that log levels above 2 on a production server can have substantial performance repercussions. – cori May 21 '09 at 15:29
  • 12
    For newer Apache versions (at least 2.4 and newer), RewriteLog/RewriteLogLevel no longer works. It has been replaced by LogLevel directive: http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#logging – ronneseth Jun 25 '15 at 17:22
7

You need to enable the rewrite log in your virtual host or server config

RewriteLog "/usr/local/var/apache/logs/rewrite.log"

see http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog

cori
  • 381
  • 1
  • 8
  • 16
  • 1
    This directive doesn't seem to be available with mod_rewrite anymore. Is there another module that provides this directive? – sinsedrix Nov 10 '20 at 00:11
  • For Apache 2.4 try: `LogLevel alert rewrite:trace3` (trace1 - trace8 are available) – site Mar 05 '22 at 18:21
1

You can configure a logfile specifically for Rewrite processing with the RewriteLog directive. The amount of logging can be selected with RewriteLogLevel.

David Schmitt
  • 2,185
  • 2
  • 15
  • 25