Forum Moderators: phranque
Here is the code I came up with (this is within a <Directory> block in httpd.conf):
RewriteEngine on
RewriteCond %{SERVER_PORT}!443$
RewriteRule ^(.*) https://domain.com/secure/$1 [R,L]
RewriteCond %{SERVER_PORT}!443$
RewriteRule ^/var/www/html/secure$ https://domain.com/secure/ [R,L]
PROBLEM #2: I want access control on this directory, so I added basic authentication to the <Directory> block in httpd.conf. However, if a user requests [domain.com...] they are prompted for authentication, then redirected to [domain.com...] then prompted for authentication again. Not only is this annoying from a user perspective, but it is a security issue because the first set of authentication credentials is passed outside of SSL (in plain text). Is there any way to only perform authentication once the SSL redirect has taken place?
I don't want a "main" domain name and a "secure" domain name - I'm really just trying to set up a single always-SSL domain name like "https://clientzone.example.com" and tell everyone who has access to that server to go to that URL - only problem being, you KNOW some users will forget the https, so I wanted to see if it was possible to redirect them without their having to remember it, AND have each user's directory protected with Apache's Basic Authentication. Maybe this isn't actually possible, though.
I suppose I could get around the problem by creating my own cgi-based authentication system or something instead of using Apache's, but that would take a long time to really do right.
Is it possible for the two <VirtualHost> blocks to have the same fully qualified domain name, one for normal http and one for SSL?
Yes, this can be done. You define two 'NameVirtualHost' directives:
NameVirtualHost 192.168.1.1:80
NameVirtualHost 192.168.1.1:443
<VirtualHost 192.168.1.1:80>
ServerName clientsite.example.com
RedirectPermanent / https://clientsite.example.com/
</VirtualHost>
<VirtualHost 192.168.1.1:443>
ServerName clientsite.example.com
(other SSL directives here)
</VirtualHost>