apache mod rewrite - how to determine what file on disk is being hit?

0

A project that I am newly working on has been around for years, and it has managed to accumulate several hundred rather complex RewriteRules within the Apache conf files.

When working with some files, I have been able to figure out which rules affect them. However, in other cases I am completely stuck at figuring it out. My method so far has been to manually look through the various conf files, and grep them for certain keywords.

Is there a better way to do this?

Some of the things which I can think of are:

  • Is there a command or REPL where I can enter a path, and it return that name of the file that it serves?
  • Is there a tool that will let you do the above, and also highlight which lines in the conf files re-wrote that rule?
  • Is there a way to inspect the log files to determine what the input path and corresponding file served path were?

... but I am not sure where to begin with any of these.

bguiz

Posted 2014-03-11T23:56:14.523

Reputation: 1 651

1Have you enabled RewriteLog? This is the easiest way to follow what rewrites are happening. – Paul – 2014-03-12T00:44:14.133

Answers

2

Please enable the RewriteLog directive that Paul mentioned above. Then set the value of the RewriteLogLevel directive to 2.

After that start to increase the value of RewrireLogLevel up to 9 until you see the necessary details recorded to the log file.

Alex Frolov

Posted 2014-03-11T23:56:14.523

Reputation: 411

0

agree with above, to enable rewrite log, simply add

RewriteLog <file-path>
RewriteLogLevel 2

to your virtualhost file, then restart apache

the man file for mod rewrite can be found here

Sverre

Posted 2014-03-11T23:56:14.523

Reputation: 338

I would have commented this, but miss some karma to do that.. sorry – Sverre – 2014-03-12T14:17:07.353