Forum Topic: Customizing logs via .htaccess don’t work
I add your code to .htaccess, but it don't work,why?
SetEnvIf Request_URI \.gif image-request SetEnvIf Request_URI \.jpg image-request SetEnvIf Request_URI \.jpe image-request SetEnvIf Request_URI \.png image-request SetEnvIf Request_URI \.ico image-request CustomLog logs/access_log common env=!image-request
- I test it at hostmonster.com webhosting, I vist
www.abc.com/test/hp.jpg, there have error: an error occurred while processing this directive
- I test it at our VPS hosting, I vist
www.abc.com/test/hp.jpg, there have a 500 error, move .htaccess to subfolder, 404 error.
Please help me,Thank you.
6 Replies to “Customizing logs via .htaccess don’t work”
It looks like the path name may be incorrect. According to the Apache Docs, it needs to be specified according to the server root. If this is the case, remember that the log file needs to be created by you and given the appropriate permissions on the server. Then, in the code, the file path must be correct, and relative to the server root, as explained here:
If, after setting up the actual log file, you aren't sure of its relative path to the server root, ask your host. They would best be able to provide that information.
Another possible issue could be that the functionality is disabled on your server. Again, ask your host if mod_log_config is enabled on the server. If not, that's the issue right there.
Thank you for your reply.
I still don't understand about error, problem at this code:
CustomLog logs/access_log common env=!image-request
Can you give me a example for set the path name?
I login to my FTP root directory, I can see these:
/access-logs/mysite.com (this is my log file)
/publice_html/ (this is my web directory)
I test these code at other hosting:
SetEnvIf Request_URI \.gif image-request CustomLog /var/log/apache2/access.log common env=!image-request
SetEnvIf Request_URI \.gif image-request CustomLog log/apache2/access.log common env=!image-request
But show same error:
less /var/log/apache2/access.log | grep /images/pic/8.gif
18.104.22.168 - - [03/Apr/2013:08:35:10 -0400] "GET /images/pic/8.gif HTTP/1.0" 304 - "-" "Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0"
Unless there is a syntax error on the server, the code should work.. as you can see it's the same code as provided in the official Apache Docs.
Even so, it looks like the issue is related to either:
a) CustomLog functionality has been disabled or is not available (ask your host)
b) And/or there is an issue with the file path.
If it's path-related, try the following:
1) Create a blank PHP file named
test.php and upload it to the same directory as the blackhole
2) Inside of
test.php, add this code:
<h3><?php echo $_SERVER['DOCUMENT_ROOT']; ?></h3> <h3><?php echo $_SERVER['PHP_SELF']; ?></h3> <h3><?php echo dirname(__FILE__);?></h3> <h3><?php echo getcwd(); ?></h3>
3) Visit that file in the browser, so the URL will be something like:
The file will display four similar paths, one of which should be the right one to use for the CustomLog directive.
I can see these:
/home/dev/domains/mydomain.com/public_html /test/test.php /home/dev/domains/mydomain.com/public_html/test /home/dev/domains/mydomain.com/public_html/test
How to write .htaccess code ?
Okay, so then for the
CustomLog directive, try using this line:
CustomLog home/dev/domains/mydomain.com/public_html/custom.log common env=!image-request
Then, make sure that the file,
custom.log exists in that location (i.e., the root of your domain), and also make sure it's writable by changing it's permissions. First try
775, then if neither of those permissions work, use
777 (which is safe because it's a plain-text file).
That should do it - let me know how it goes.