Why is my Apache in an infinite redirection loop?

We currently have an internal site set up for IT at it.example.com, which hosts a single Redmine site.

I want to set up Apache so that if a user goes to kb.example.com it redirects them to http://it.example.com/some/path/to/knowledge-base as a shortcut.

I added a <VirtualHost> at the end of my httpd.conf, and now whenever I try to hit the main site (it.example.com) the browser goes into an infinite redirection loop:

http://it.example.com/projects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-base

Here is my httpd.conf:

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-4.0.37/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
  PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-4.0.37
  PassengerDefaultRuby /usr/bin/ruby
</IfModule>

ServerName it.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/redmine-2.4.3/public
ErrorLog logs/redmine_error_log
SetEnv RAILS_ENV production
SetEnv RailsEnv production

#If you are using mod_fcgid and are going to upload files larger than
 #131072 bytes you should consider adding the following line
#that allows to upload files up to 20 mb
MaxRequestLen 20971520

<Directory "/var/www/redmine-2.4.3/public">
    Options Indexes ExecCGI FollowSymLinks -MultiViews
    Order allow,deny
    Allow from all
    AllowOverride all
</Directory>

<VirtualHost *:80>
  ServerName kb.example.com
  Redirect / http://it.example.com/projects/knowledge-base
</VirtualHost>

So it looks like the VirtualHost is being ignored and the rules for kb.example.com are ALWAYS in effect - thus causing the infinite redirect...


Solution 1:

I think you need to wrap your existing it.example.com definition in a <VirtualHost> block. I think this is being caused because without the vhost definition for it.example.com, kb.example.com becomes the default vhost. In the event that a suitable vhost isn't found this is what will be served which then comes back to itself ...