Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite and error log

mod_rewrite error message

         

mugd

5:28 am on Jun 23, 2007 (gmt 0)

10+ Year Member



Hi everyone. I have a little problem I can't seem to find a solution for. Hopefully there is one. I am using mod_rewrite on my url's, for instance, I have:

http://example.com/profile.php?user=john

with my rewrite rule
RewriteRule ^profile/([^/]*)\.php$ profile.php?user=$1 [L]
which translates to http://example.com/profile/john.php

The rule is working just fine, but it keeps throwing errors in error_log, like...
File does not exist: /path/to/script/profile, referer: [example...]

It acts the same with all the rules I have. Is there a way to NOT show these error messages?

[edited by: jdMorgan at 10:01 pm (utc) on June 23, 2007]
[edit reason] example.com [/edit]

mugd

3:41 am on Jun 25, 2007 (gmt 0)

10+ Year Member



anyone? please?!

jdMorgan

2:35 pm on Jun 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you mean that all of your rewrites function, but that each rewrite also results in an error log entry?

This would be extremely odd, and the only way I can think of that it could happen is if you (or someone) is using a custom 404 error document as the mechanism to pass control to your script URLs -- or perhaps to all of your files. This practice was fairly common before it became standard for hosting companies to allow their customers (Webmasters) to use mod_rewrite, but it causes many problems, and some sounded similar to this one, if I remember correctly.

Jim

mugd

1:17 pm on Jun 30, 2007 (gmt 0)

10+ Year Member



That is right, all my rewrites are functional, but each one produces an entry in the error_log file. I'm not using any hosting services, this is happening on my own machine, running apache 2.2.4.
Any ideas of what I could try?

Thanks again for your time!

jdMorgan

3:45 pm on Jun 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is either a serious server misconfiguration/corrupt installation, or perhaps the problem is actually downstream from the rewrites, and is simply a missing file in your scripting support.

First thing I'd be looking at is the specific filepath shown in the error log? What is "/path/to/script/profile" and where is it defined? Having determined that will likely give you an idea how to fix it.

Jim

[edited by: jdMorgan at 3:45 pm (utc) on June 30, 2007]

mugd

7:38 pm on Jun 30, 2007 (gmt 0)

10+ Year Member



This is the full message that is shown (one of the many):

File does not exist: /var/www/htdocs/lowtube/profile, referer: [80.81.82.83...]

The rule I am using is listed in my first post. The IP address I used in this post does not reflect my actual IP address.

jdMorgan

8:04 pm on Jun 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, open up the file /var/www/htdocs/lowtube/profile/mugd.php, examine the code, and look for where it does an HTTP GET or PUT to example.com/lowtube/profile

The latter file does not exist, and the script is requesting it, so you're getting an error.

I don't know your site, so perhaps the "lowtube" part of the URL-path I cited is actually part of the filepath. But the mugd.php script is requesting a bad path, and that's causing an error.

Jim

mugd

8:21 pm on Jun 30, 2007 (gmt 0)

10+ Year Member



I think I'm not explaining the situation properly, or there is a miss-understanding.

All the files I am working on/with are in the folder called "lowtube", which exists, and is in the documentroot path, which is /var/www/htdocs.

The file mugd.php doesn't actually exist.
My rewrite rule is translating profile.php?user=mugd to profile/mugd.php

using this rule:
RewriteRule ^profile/([^/]*)\.php$ profile.php?user=$1 [L]

So when I access [80.81.82.83...] the error_log says:
File does not exist: /var/www/htdocs/lowtube/profile, referer: [80.81.82.83...]

...but the page displays properly, with no errors. The only thing that upsets me is the errors that keep popping up in the log file, even though everything is working just fine.

I hope that makes it easier to understand.

jdMorgan

9:23 pm on Jun 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you on Apache 2.x? Do you have AcceptPathInfo turned on? If so, turn it off.

Notice that the "file" that it reports does not exist is not a file, nor is it the URL you requested, nor is it the filepath you're rewriting to, either. So something is either diverting the request before your RewriteRule can act on it, or is taking action after your rule is applied, and interfering with operations.

Also, for the sake of clear discussion, your rule is "translating" the requested URL
http://example.com/profile/john.php to the server filepath /var/www/htdocs/lowtube/profile.php?user=john

It helps to keep URLs and filepaths clear, and also to understand the "direction" of the rewrite, which occurs in the URL-to-filename translation phase of the Apache API, after the request is received by Apache and before any content-handlers are activated or any scripts are invoked.

As I stated, this is a weird problem, otherwise the solution would be obvious.

As far as your code goes, I'd suggest a couple of small regex improvements for efficiency, but this has nothing to do with the problem in all likelihood:


RewriteRule ^profile/([^/.]+)\.php$ profile.php?user=$1 [L]

I added "." (literal period) to the "stop match" character group, and changed "*" to "+" so that a blank name is not accepted.

However, this looks more like a PathInfo problem. To explain: There are two main methods to deliver a request for a "fake" directory/file to a script and pass data to that script. The first way is the one you're trying to use, which is to use mod_rewrite to convert a static URL into a script invocation with the data passed in a query string, i.e. "user=john".

The other method, available on Apache 2.0 and later only, is to use AcceptPathInfo [httpd.apache.org]. What AcceptPathInfo does is to catch requests which result in "404 - Not found" errors, and retry them after removing the last path-part from the file path to which the requested URL resolves. It then puts the part it removed into a server variable called PathInfo which is available to scripts. So in this case, when the file "/profile/john.php" is not found, "john.php" is removed from the path, leaving the path as /profile and the PathInfo value as "john.php". Then the request is retried as "/profile" and this is when the error pops up.

Now, how or why your script would still work after this happens is a mystery to me. But nonetheless, the symptoms indicate it's something to do with AcceptPathInfo. If you're on Apache 1.x, this theory becomes immediately worthless, so let me know... :)

Jim

mugd

9:49 pm on Jun 30, 2007 (gmt 0)

10+ Year Member



I am using apache 2.2.4
How do I disable AcceptPathInfo? I tried adding AcceptPathInfo Off to .htaccess but I don't notice any differece. The errors are still showing.

jdMorgan

7:05 pm on Jul 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is the correct way to disable it. But I'll have to admit that I'm stumped, and if any solution is to be found, it will have to be either you or a fresh set of eyeballs to find it.

There is no 'tricky' reason that the code above might not work -- It's not particularly complicated code, it ought to work without a fuss, and I don't know why it's throwing errors.

Jim