I'm trying to set up a subdomain using name-based Virtual Hosts, according to the configuration format in this question.
As I understand it, this:
Finally, you can fine-tune the configuration of the virtual hosts by placing other directives inside the containers. Most directives can be placed in these containers and will then change the configuration only of the relevant virtual host. To find out if a particular directive is allowed, check the Context of the directive. Configuration directives set in the main server context (outside any container) will be used only if they are not overridden by the virtual host settings.
should mean that the task of moving from a single host to 1 host + 1 subdomain should be fairly straightforward. However, when I add the VirtualHost directives, I run into problems.
First off (and pretty catastrophic) is that the home page for the main domain returns a 403 (Forbidden). Could any of the following be causing that:
- The existing main domain has a large configuration file, with many settings. I'm placing the
VirtualHostdirectives near the end of
httpd.conf, just after the commented out instructions for virtual hosts
- There are lots of
Rewrites in a file that's included after the
VirtualHosts - could they be clashing?
- I've put the absolute minimum in the
VirtualHostdirectives, because I want to keep it as simple as possible. Would it be better to move the contents of the old
httpd.confinto a separate file (e.g. main-domain.conf),
Includethat in one
VirtualHostand create a separate conf file for the sub-domain, including that in the second
- Finally, is there any simple way of debugging this, bearing in mind I'm working with a live site, so any changes have to be tested very quickly!
OK, the error is, more specifically:
Directory index forbidden by rule
Other pages appear to work OK, so it must be some kind of problem with a redirect from the homepage. I guess this was partly why I asked if there are known clashes between VirtualHost setups and
<Directory "/path/to/docroot"> block that matches the
DocumentRoot in a
VirtualHost block be before or after the latter (or doesn't it matter)?
OK, so it looks like what's not happening is the following redirect:
RewriteRule ^/$ /path/to/something/else [PT]
which I'm guessing is happening for one of two reasons:
The current config isn't even attempting to process this rewriterule. The rule itself is in an
Included file, after the
The rule is no longer matching because the
VirtualHostdirective is causing the pattern match to fail. This seems, to me, by far the most likely ...
Anyone think this might be relevant?
Note that, by default, rewrite configurations are not inherited. This means that you need to have a RewriteEngine on directive for each virtual host in which you wish to use it.
In other words, does that mean I need to:
<VirtualHost *:80> RewriteEngine on </VirtualHost>
for each VH that needs to handle Rewrite* stuff, rather than just relying on
RewriteEngine on in the globally-included file?
Sadly, the change referred to in Update 3 hasn't fixed the problem at all