Forum Moderators: phranque
First post and I'm not an apache expert by any means so please bear with me! :)
From reading the Apache documentation, my understanding is that the .htaccess file can perform the same roles as the main configuration files (e.g. default-server.conf), but at a user level rather than system admin level. I'm wanting to configure a virtual host in such a way that its behaviour can be controlled in the .htaccess file if this is possible. I don't mind if the basic configuration is done in the vhosts.d directory but I want things like redirects, proxy redirection and so on for that vhost to be controlled in the .htaccess file.
If this helps, here's an example:
Host www.foo.com has a vhost configured (in vhosts.d for example) to point to itself:
<VirtualHost _default_:80>
DocumentRoot /home/html/
ServerName www1.foo.com
</VirtualHost>
In the .htaccess file sitting in /home/html/.htaccess, I then want to be able to start writing specific customizations for that particular host. Obviously both www.foo.com and www1.foo.com will read the same .htaccess file so I need to indicate that the customizations are only for www1.foo.com. However any attempts to start to do this (such as proxy commands) have given me 500 errors.
Can what I'm wanting be achieved, and if so, how?
Thanks!
Greg
It is likely that the directives which are causing your 500-Server Errors are not allowed in an .htaccess context.
Only some of the configuration options available at the server config level or at the <VirtualHost> level are available at the .htaccess level. The levels at which particular directives are available depends primarily on their security implications.
Jim
If so then Proxy commands can go in the .htaccess file but they would have to apply to any server which reads that .htaccess file, i.e. there's no way of linking them to a particular virtual host - is this correct? I'm really hoping there's some way we can use the .htaccess file to control the proxying of certain directories by linking them to a particular virtual host.
Thanks,
Greg
The .htaccess mechanism is there to essentially allow users software level control over domain space, in other words to tweak behaviour as it applies to directories, locations, files. Such objects might reasonably be expected to change either frequently, or to differ across objects within a site.
The main httpd file mechanism allows Admin level control over DOMAINS (and objects), which are not expected to change that frequently. The httpd configs are only consulted on startup or refresh of the main daemon. The .htaccess files are consulted every time Apache looks into a directory, or consults a location or file. [indeed some folks turn off the facility because of the potential overhead to processing it causes, personally I think this is generally negligible].
So, if in doubt, and if you can't get hold of the instance table for the Directive from the manual, ask whether its a setting that you would expect to apply to a domain rather than an object (or indeed software for instance turning on register globals selectively in .htaccess per directory);
For example, setting the ServerName is something you would never expect to do on a per directory basis, it would make no sense to the protocol to have the server swap domain addresses as it traversed a directory tree previously applied to a particular domain as its DocumentRoot.
On the other hand, allowing access to a directory, swapping the default index file for a directory, these are clear examples of a .htaccess level of administration duty.
best
Steve