RewriteLog triggers Internal Server Error - apache

I am trying to do some debuging on my rewrite rules and wanted to enable RewriteLog to view how they are interpreted.
but when i activate it i get Internal Server Error
heres the line:
RewriteLog "/home/solomongaby/www/project/logs/rewrite.log"
thanks

The RewriteLog directive is only allowed in the server or virtual host configuration (see Context value).

You should post whole string from apache log file to be sure, but i suspect that you've tried to add this string in .htaccess and it gives you error "you can't have rewrite log directive here".
P.s. it's
RewriteLog "/home/solomongaby/www/project/logs/rewrite.log"
and not
RewriteLog "/home/solomongaby/www/project/logs/rewrite.log
Right?

It's most likely a permissions issue. Check Apache's error.log file.

Related

Custom errors in apache config files (not error pages)

I'm not looking to create custom error pages, but to actually issue error messages when the config file is parsed. Specifically, I want to use an <IfModule> to throw up an error if the module hasn't been loaded, so it's easier to debug.
This is the only kludgy thing I could think of (and requires mod_rewrite enabled):
<IfModule !mod_deflate.c>
ErrorDocument 500 "mod_deflate isn't available"
RewriteEngine On
RewriteRule .* - [R=500]
</IfModule>
If you find a better way to 'trigger' errors, I'm certainly interested ;)
For Httpd 2.4 see http://httpd.apache.org/docs/2.4/en/mod/core.html#error
For older versions
<IfModule !mod_deflate.c>
Mod_deflate_not_enabled.
</IfModule>
will raise something like
Syntax error on line 7 of /etc/apache2/sites-enabled/000-default:
Invalid command 'Mod_deflate_not_enabled.', perhaps misspelled ...
...fail!
when you reload the server config.

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.

Apache mod_speling case insensitive URLs issue

I want to have case insensitive URLs using Apache's mod_speling module, but this is producing unwanted lists of "multiple options" whilst the Apache documention says
When set, this directive limits the action of the spelling correction to lower/upper case changes. Other potential corrections are not performed.
I'm testing this on an Apache 2.2.16 Unix fresh install but I'm still running into exact the same problems as submitted in 2008.
It's unexpected (and not wanted) behaviour when Apache lists a few "multiple choices" (status code 300) when the checkCaseOnly directive is on!
I have this in my httpd.conf:
CheckSpelling on
CheckCaseOnly on
First directive to use the mod_speling, second directive to limit only to case corrections
What am I doing wrong?
TLDR: CheckCaseOnly is broken due to a bug that has remained unfixed for over six years as of 10/2014.
I know this is an old question, but I just ran into the same issue. This update is to help others with the same issue.
The current answers to this question are incorrect, as the OP is using mod_speling correctly, but there is a bug.
https://issues.apache.org/bugzilla/show_bug.cgi?id=44221
The underlying issue is that the apache people are in disagreement over fixing this behavior because it changes the rest of the module. This has remained unfixed for something like 6 years.
To enable mod_speling (either by Location or VirtualHost) use the directive:
CheckSpelling On
If all you want is case insensitivity use:
CheckCaseOnly On
You also need to have RewriteEngine enabled:
RewriteEngine On
On Ubuntu 12.04 LTS using Apache 2.2, I did the following:
Create speling.conf in ${APACHE}/mods-available to provide the config options.
<IfModule mod_speling.c>
CheckSpelling On
CheckCaseOnly On
</IfModule>
Link speling.conf and speling.load into the enabled modules directory ${APACHE}/mods-enabled:
# cd ../mods-enabled
# ln -s ../mods-available/speling.conf speling.conf
# ln -s ../mods-available/speling.load speling.load
Restart the server.
# service restart apache2
After reading user1647075's answer about this being a known Apache bug that's unlikely to be fixed, I decided my best option was to hide the "multiple options" page from the user by updating my Apache config to show the 404 error page for 300 status codes:
ErrorDocument 300 /404.htm
Of course, you can also create a custom error page instead of reusing the 404 error page.
Hope this workaround helps.
Do you really want case insensitive URL?
Why not just force lowercase urls, like this?
RewriteEngine On
RewriteMap lc int:tolower
RewriteRule (.*) ${lc:$1} [R]
Have a look at http://www.issociate.de/board/post/265865/make_URL

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.