Apache mod_rewrite logging - apache

I can't get mod_rewrite to log anything about what it's doing. You can imagine that this makes debugging mod_rewrite... challenging. I've followed the "instructions" at http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html (I'm running 2.2.22 on a Mac), except that they're missing critical details like... which of the config files to put the configuration in, and in which level of XML elements.
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 8
Where do I put these directives so that I actually get logging about what mod_rewrite is doing? /tmp/rewrite.log is created, so Apache has some clue about what I want, but it logs nothing at all to this file.

Related

.htaccess created or modified: do I have to restart Apache? [duplicate]

This question already has answers here:
Do you have to restart apache to make re-write rules in the .htaccess take effect?
(7 answers)
Closed 7 years ago.
I am trying to debug some .htaccess problems on Apache but I am new to mod_rewrite.c. I would like to know whether I need to restart Apache in XAMPP whenever I make modifications to the .htaccess files, or whether these are parsed and applied whenever a web page is served independently of whether Apache is restarted.
A restart is not required for changes to .htaccess. Something else is wrong.
Make sure your .htaccess includes the statement
RewriteEngine on
which is required even if it's also present in httpd.conf. Also check that .htaccess is readable by the httpd process.
Check the error_log - it will tell you of any errors in .htaccess if it's being used.
Putting an intentional syntax error in .htaccess is a good check to make sure the file is being used -- you should get a 500 error on any page in the same directory.
Lastly, you can enable a rewrite log using commands like the following in your httpd.conf:
RewriteLog "logs/rewritelog"
RewriteLogLevel 7
The log file thus generated will give you the gory detail of which rewrite rules matched and how they were handled.
Do you have to restart apache to make re-write rules in the .htaccess take effect?

Apache RewriteLog only on specific IP?

I have logging enabled in my httpd conf file as follows...
RewriteLog "/var/log/httpd/rewrite.log"
RewriteLogLevel 3
This works fine. I don't want to impact the server whilst debugging though, or create extra info than needed.
Is there any way to only log rewrites only for a specific IP address (or narrow via some other criteria if not)?
One solution I've found so far is the pipe operator, so I've added the following...
RewriteLog "|/bin/grep '<myIpAddress>' > /var/log/httpd/debugrewrite.log"
RewriteLogLevel 5
Not sure how efficient that is, as it calls grep each time, so I'm not a fan of it, but for the moment its helping cut down the logging, and I turn it off as soon as finished.

Log of Apache rewrites

I'm getting a "webpage has a redirect loop" error. Most likely this is due to my Apache rewrite configuration. I've had these issues before, and find them hard to debug. Is there some sort of log that allows me to see what the request is being redirected to?
If not, how do you debug Apache rewrites in an efficient way?
If you are using newer Apache version (I'm testing it with 2.4), the RewriteLog directive has been replaced by the new per-module logging configuration (see apache doc).
Now you want to put the following line in your configuration:
LogLevel alert rewrite:trace3
and check your error log for the rewrite module messages.
tail -f error_log|fgrep '[rewrite:'
You can configure mod_rewrite's log file via the "RewriteLog" directive.
For example:
RewriteLog "/usr/local/var/apache/logs/rewrite.log"
For more information, see: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog
One other link I find myself going back to is "crazy advanced mod_rewrite" -- lots of info there which you may want to stash away for future reference. It's at: http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html
See RewriteLog and RewriteLogLevel directives.

RewriteLog and RewriteLogLevel in MAMP

I need to set my RewriteLogLevel in MAMP to figure out some mod_rewrite problems.
I put the below lines in my httpd.conf and my local .htaccess file, but I am not finding a output log. How do I set this up correctly?
RewriteLogLevel 9
RewriteLog "rewrite.log"
Try using a full path like /var/log/httpd/rewrite.log.
Also make sure you have mod_rewrite turned on.
Apache generally doesn't enable mod_rewrite by default, so you may need to add more entries to your httpd.conf file.
For instance, did you put in an entry for LoadModule that points to the mod_rewrite.so module?
Check this link for details:
http://michaelkrol.com/2005/11/21/enable-mod_rewrite-on-os-x-104-tiger/
Also, don't forget to restart Apache to test your changes.

Do you have to restart apache to make re-write rules in the .htaccess take effect?

I have pushed my .htaccess files to the production severs, but they don't work. Would a restart be the next step, or should I check something else.
A restart is not required for changes to .htaccess. Something else is wrong.
Make sure your .htaccess includes the statement
RewriteEngine on
which is required even if it's also present in httpd.conf. Also check that .htaccess is readable by the httpd process.
Check the error_log - it will tell you of any errors in .htaccess if it's being used.
Putting an intentional syntax error in .htaccess is a good check to make sure the file is being used -- you should get a 500 error on any page in the same directory.
Lastly, you can enable a rewrite log using commands like the following in your httpd.conf:
RewriteLog "logs/rewritelog"
RewriteLogLevel 7
The log file thus generated will give you the gory detail of which rewrite rules matched and how they were handled.
No:
Apache allows for decentralized management of configuration via special files placed inside the web tree. The special files are usually called .htaccess, but any name can be specified in the AccessFileName directive... Since .htaccess files are read on every request, changes made in these files take immediate effect...
From the apache documentation:
Most commonly, the problem is that AllowOverride is not set such that your configuration directives are being honored. Make sure that you don't have a AllowOverride None in effect for the file scope in question. A good test for this is to put garbage in your .htaccess file and reload. If a server error is not generated, then you almost certainly have AllowOverride None in effect.
Only if you have not added the mod_rewrite module to Apache.
You only need to restart Apache if you change any Apache ".conf" files.
I have the same issue and it seems PiedPiper post about AllowOverride were most helpful. Check your httpd.conf file for "AllowOverride" and make sure it is set to All.
In case of .htaccess restart is not required if it is not working probable reasons include.
AllowOverride May not be set which user can set inside httpd.conf or might have to contact server admin.
Check the file name of .htaccess it should be .htaccess not htaccess.txt see here for guide how to create one.
Try to use Options -Indexes or deny all kind of simple directive to see if it is working or not.
clear browser cache everytime if having rule for redirects or similar if previous redirect is cached it appears as if things are not working.
What's in your .htaccess? RewriteRules? Check that mod_rewrite is installed and enabled.
Other stuff? Try setting AllowOverride to 'all' on that directory.