Forum Moderators: phranque
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]
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
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]
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.
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
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.
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]
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
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