{

    use esmith::util;

    if ( $port ne ($modSSL{'TCPPort'} || '443')){
        $OUT .=<<"EOF";

    #====================================================================
    # HTTPS redirection for LemonLDAP::NG Manager
    #====================================================================

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*
    RewriteRule ^/(.*|\$) https://%{HTTP_HOST}/\$1 \[L,R\]
EOF
    }
    else{
        my $authtype = $lemonldap{'ManagerAuth'} || 'basic';
        my $auth = '';
        my $base = esmith::util::ldapBase($DomainName);

        unless ( $authtype eq 'self' ) {
            $auth = "AuthName 'LemonLDAP NG Manager Interface'\n" .
                    "        AuthType Basic\n" .
                    "        AuthBasicProvider ldap\n" .
                    "        AuthLDAPURL ldap://localhost/ou=Users,$base?uid\n" .
                    "        AuthLDAPGroupAttribute memberUid\n" .
                    "        AuthLDAPGroupAttributeIsDN off\n" .
                    "        require ldap-user admin";
        }

        $OUT .=<<"EOF";

    SSLEngine On

#    PerlOptions +Parent

    #====================================================================
    # Apache configuration for LemonLDAP::NG Manager
    #====================================================================
    # FASTCGI CONFIGURATION
    # ---------------------

    # 1) URI management
    RewriteEngine on

    # For performances, you can delete the previous RewriteRule line after
    # puttings html files: simply put the HTML results of differents modules
    # (configuration, sessions, notifications) as manager.html, sessions.html,
    # notifications.html and uncomment the 2 following lines:
    # DirectoryIndex manager.html
    # RewriteCond "%{REQUEST_URI}" "!\.html(?:/.*)?\$"

    # REST URLs
    RewriteCond "%{REQUEST_URI}" "!^/(?:static|doc|lib|javascript|favicon).*"
    RewriteRule "^/(.+)\$" "/manager.fcgi/\$1" [PT,L]

    RewriteCond "%{REQUEST_URI}" "!^/(?:static|doc|lib|javascript|favicon).*"
    RewriteCond %{DOCUMENT_ROOT}/\$1 !-f
    RewriteRule ^/(.*)\$ /manager.fcgi/\$1 [PT,L]

    # 2) FastCGI engine
    # You can choose any FastCGI system. Here is an example using mod_fcgid
    # mod_fcgid configuration
    FcgidMaxRequestLen 2000000
    <Files *.fcgi>
        SetHandler fcgid-script
        Options +ExecCGI
        header unset Lm-Remote-User
        # INDISPENSABLE pour éviter l'erreur 400 Bad Request :
        CGIPassAuth On
    </Files>

    # If you want to use mod_fastcgi, replace lines below by:
    #FastCgiServer /usr/share/lemonldap-ng/manager/htdocs//manager.fcgi

    # GLOBAL CONFIGURATION
    # --------------------
    # DocumentRoot
    DocumentRoot /usr/share/lemonldap-ng/manager/htdocs/
    <Location />
        Require all granted

        <IfModule mod_deflate.c>
            AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css
            SetOutputFilter DEFLATE
            BrowserMatch ^Mozilla/4 gzip-only-text/html
            BrowserMatch ^Mozilla/4\.0[678] no-gzip
            BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
            SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
        </IfModule>
        <IfModule mod_headers.c>
            Header append Vary User-Agent env=!dont-vary
        </IfModule>
    </Location>
    # Static files (javascripts, HTML forms,...)

    Alias /static/ /usr/share/lemonldap-ng/manager/htdocs/static//
    <Directory /usr/share/lemonldap-ng/manager/htdocs/static/>
        Require all granted
        Options +FollowSymLinks
    </Directory>

    # On-line documentation
    Alias /doc/ /usr/share/lemonldap-ng/doc/
    Alias /lib/ /usr/share/lemonldap-ng/doc/pages/documentation/current/lib/
    <Directory /usr/share/lemonldap-ng/doc/>
        Require all granted
        ErrorDocument 404 /notfound.html
        Options +FollowSymLinks
        DirectoryIndex index.html start.html
    </Directory>


    <Directory /usr/share/lemonldap-ng/manager/htdocs/>
        DirectoryIndex manager.fcgi index.fcgi index.html
        Options +ExecCGI +FollowSymlinks
        <RequireAll>
        require ip $localAccess $externalSSLAccess
        $auth
        </RequireAll>
    </Directory>

#    Alias /fr-doc/ /var/lib/lemonldap-ng/fr-doc/
#    <Directory /var/lib/lemonldap-ng/fr-doc/>
#        Require all granted
#        ErrorDocument 404 /notfound.html
#        Options +FollowSymlinks
#        DirectoryIndex index.html start.html
#    </Directory>

    # Directory index
    <IfModule mod_dir.c>
        DirectoryIndex index.fcgi index.html
    </IfModule>

    <Location /doc/>
        <IfModule mod_expires.c>
                ExpiresActive On
                ExpiresDefault "access plus 1 month"
        </IfModule>
    </Location>
    <Location /skins/>
        <IfModule mod_expires.c>
                ExpiresActive On
                ExpiresDefault "access plus 1 month"
        </IfModule>
    </Location>
EOF
    }
}

