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.
Related
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.
I was trying out the Apache Rewrite Engine, but was having problems because it cached it's responses. Now if I change the file, it does not do what the file says, but does what it did when I tried the same url before.
For example, I tried to type in
localhost/api
but I had not yet set a rule that would match that. The server gave me a 404 error. I tried to add a rule that would work with this url:
RewriteRule api/? api.php [L]
but it still gave me the same error. If I try an address like localhost/lapi which I didn't enter before I added the rule, it works. Is there a way to clear this cache and restart? I tried restarting apache using apachectl -k restart and apachectl -k graceful but I still had the same problem. Does anyone know how to fix this problem?
First of all, depending on the context of your rule, you may need a leading slash as in:
RewriteRule api/? /api.php [L]
Regarding the caching, do you have mod_cache enabled? If so, disable it and restart your server. mod_rewrite does not do any caching on its own. Also be sure to completely clear your browser cache and be aware that if you are not accessing your server over the same local network, there may be other caching taking place along the way.
This problem can also be caused by the MultiViews option, see Apache doc. Try omitting Option MultiViews from httpd.conf or add Options -MultiViews to .htaccess.
(The MultiViews option enables Apache to choose automaticaly between several versions of the file based on the file name extension and content preferences present in the HTTP request (i.e. something you probably don't want to happen). It can lead to this kind of bizzare failure when a rewrite rule just removes the script's extension.)
I just installed a fresh copy of Drupal 6.19 to get to speed on how to write modules. But for some reason the rewrite module isn't working for Drupal.
What I have checked:
$ apachectl -M >> it is installed
php_info() on current server >> says rewrite is installed also
I also double-checked the .htaccess file in my Drupal root folder
UPDATE: checked httpd.conf for AllowOverride All
I'm out options here. Looked everywhere but the Drupal settings aren't letting me to enable the settings and their test is simply visiting a site that should work if the rewrite module was there.
My specs:
Mac OS X 10.6 Snow Leopard
Using built-in Apache with PHP5
Thanks!
Last but not least, you must authorize your virtual host or directory to use .htaccess.
AllowOverride All
Update:
I can't figure out your exact problem but it's always worth testing that Apache is actually parsing your .htaccess file. Make a syntax error on purpose and see if you get a 500 Internal Server Error message. Also, test mod_rewrite with a simple redirection rule that doesn't involve Drupal.
Two more things to check:
Verify that your .htaccess is readable for your apache processes (Yes, I read that you double checked it, but did that include the file permissions?)
Enable rewrite logging - this might give you some hints on where it fails. Start with a log level of 5 and increase/decrease as needed. (Don't forget to turn it off again later, as it is a huge performance hog ;)
Also, I'd try to simplify the test scenario - start with a simple rewrite directive in a vhost configuration. Once that works, move it to a .htaccess in the top-level of the vhosts document root, then to sub directories (if needed/used).
Make sure that if the install is in a sub-directory that the username is part of the rewriteBase
# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
RewriteBase /~username/drupal**
If you running your Drupal installation in a sub-folder like: example.com/drupal, then enable "RewriteBase /" in your .htaccess file, it might help you.
A clean url could be something like www.example.com/fisherman instead of www.example.com/data/pages/fisherman.php
Some installations of apache have clean URL functionality out of the box. There are 2 steps that need to be configured correctly for it to work.
Enable rewrite module
Allow .htaccess file overrides
Both steps require SSH root access to your server. So if you are on shared host this probably won't work for you. Open your terminal:
Enable rewrite module
To enable the rewrite module, you can type the following command
sudo a2enmod rewrite
Now type
sudo service apache2 restart
to enable the changes. You can check if it’s working by typing
sudo apache2ctl –M
A list will appear. Look for “rewrite_module”.
http://codeontrack.com/enable-clean-urls-apache/
Look for this Line in your httpd.conf file
#LoadModule rewrite_module modules/mod_rewrite.so
If commented
Just uncomment it restart apache server then try enabling in drupal administer Clean URL Section
I added the following to my .htaccess file and it was solved. My problem was specifically hapening with Rackspace / CentOS image
Options -MultiViews
As Álvaro G. Vicario mentioned, the first thing to do is at the top of the .htaccess file add something like ghfdiddfdjf which should throw an internal error. If it doesn't, you know the .htaccess file isn't being read. Mine wasn't, and I found the following fix:
In the etc/apache2/sites-enabled folder, there was a file called default-000. It was in this file that I changed AllowOverride All in 2 places in the file.
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
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.