<VirtualHost *:80>
    ServerName wiki.my-wiki-domain.org
    ServerAdmin wiki-admins@my-wiki-domain.org
    ServerAlias twiki.my-wiki-domain.org.br

    DocumentRoot /usr/lib/cgi-bin/foswiki
    Alias /pub /path/to/my-wiki-dir/www/foswiki/pub
    Alias /twiki/pub /path/to/my-wiki-dir/www/foswiki/pub
    Alias /foswiki/pub /path/to/my-wiki-dir/www/foswiki/pub

    Include /path/to/my-wiki-dir/conf/wiki-block-access.conf

    # Block access to typical spam related attachments
    # Except the TWiki directory which is read only and does have attached 
    # html files.
    SetEnvIf Request_URI "foswiki/pub/.*\.[hH][tT][mM][lL]?$" blockAccess
    SetEnvIf Request_URI "foswiki/pub/System/.*\.[hH][tT][mM][lL]?$" !blockAccess

    RewriteEngine On

    # authentication via HTTPS
    RewriteRule ^/login(/.*)?$  https://wiki.my-wiki-domain.org/login$1        [R]

    # redirect the old "twiki" to "wiki"
    RewriteCond %{HTTP_HOST} ^(www\.)?twiki.my-wiki-domain.org$
    RewriteRule ^/(.*)?$ http://wiki.my-wiki-domain.org.br/$1 [R,L]

    # compatibility with old installation "/bin/<action>":
    # /bin/<action>/<PageName> -> /<action>/<PageName>
    RewriteRule ^/bin/view(/.*)?$ $1 [R=301]
    RewriteRule ^/bin(/.*)?$ $1 [R=301]

    # short URLs
    # wiki.my-wiki-domain.org/<PageName> -> wiki.my-wiki-domain.org/view/<PageName>
    RewriteRule ^(/([A-Z].*)?)?$ /view$1 [L]

    # from /etc/foswiki/apache.conf
    <Directory /usr/lib/cgi-bin/foswiki/>
        BrowserMatchNoCase ^$ anonymous_spider
        Order Allow,Deny
        Allow from all
        Deny from env=anonymous_spider
        Deny from env=blockAccess

        ErrorDocument 401 /System/UserRegistration

        Options ExecCGI FollowSymLinks
        SetHandler cgi-script
        #SetHandler perl-script
        #PerlHandler ModPerl::Registry
        #PerlSendHeader On
        AllowOverride all
        Allow from all
    
        <FilesMatch "^configure">
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1
	    AuthType Basic
	    AuthName "Foswiki Configuration"
            AuthUserFile /path/to/my-wiki-dir/passwd/.htpasswd
            AuthGroupFile /path/to/my-wiki-dir/passwd/.htgroup
            Require group wiki
            Satisfy Any
        </FilesMatch>
    </Directory>

    ErrorLog /path/to/my-wiki-dir/log/apache2/error.log
    LogLevel warn
    CustomLog /path/to/my-wiki-dir/log/apache2/access.log combined

    ServerSignature On
</VirtualHost>
<VirtualHost *:443>
    # basically the same as above
</VirtualHost>
