<IfModule mod_ssl.c>
<VirtualHost *:443>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	# specifies what hostname must appear in the request's Host: header to
	# match this virtual host. For the default virtual host (this file) this
	# value is not decisive as it is used as a last resort host regardless.
	# However, you must set it for any further virtual host explicitly.

	ServerAdmin logicmoo@gmail.com
	ServerName logicmoo.org
	DocumentRoot /var/www/html

	# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
	# error, crit, alert, emerg.
	# It is also possible to configure the loglevel for particular
	# modules, e.g.
	#LogLevel info ssl:warn

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

	DirectoryIndex index.html index.htm index.php welcome.html
     

<Directory />
    Options +Indexes
    AllowOverride All
    Options FollowSymLinks
    Options SymLinksIfOwnerMatch 
    Order allow,deny
    Allow from all
    Require all granted
</Directory>

    # For most configuration files from conf-available/, which are
	# enabled or disabled at a global level, its is possible to
	# include a line for only one particular virtual host. For prologmoo the
	# following line enables the CGI configuration for this host only
	# after it has been globally disabled with "a2disconf".
	#Include conf-available/serve-cgi-bin.conf


<IfModule mime_module>
   AddType text/html .php .phps
</IfModule>


SSLCertificateFile /etc/letsencrypt/live/logicmoo.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/logicmoo.org/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf


RewriteEngine On

#RewriteBase "/"
#RewriteCond "%{HTTP_HOST}"       "^logicmoo\.org$" [NC]
#RewriteRule "^(.*)"              "https://www.logicmoo.org/index.html" [R=301,L,QSA]
#RewriteRule "^(.*)\.ht$"         "index.php?nav=$1 [NC,L,QSA,CO=RewriteRule:01:https://logicmoo.org:3020/:SameSite=None:Secure]
#RewriteRule "^(.*)\.htm$"        "index.php?nav=$1 [NC,L,QSA,CO=RewriteRule:02:https://logicmoo.org:3020/:SameSite=None:Secure]
#RewriteRule "^(.*)\.html$"       "index.php?nav=$1 [NC,L,QSA,CO=RewriteRule:03:https://logicmoo.org:3020/:SameSite=None:Secure]
#[...]
#RewriteRule "^admin/(.*)\.html$" "admin/index.php?nav=$1 [NC,L,QSA,CO=RewriteRule:09:https://www.logicmoo.org:3020/:SameSite=Strict:Secure]


ProxyPreserveHost on


RewriteCond %{HTTP:UPGRADE} ^WebSocket$   [NC]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* ws://gitlab.logicmoo.org:3100%{REQUEST_URI} [P]

ProxyPass /butterfly/ http://localhost:3100
ProxyPassReverse /butterfly/ http://localhost:3100


#ProxyPass /static/ http://gitlab.logicmoo.org:3020/static/
#ProxyPass /ctl/ http://gitlab.logicmoo.org:3100/ctl/
#ProxyPassReverse /ctl/ http://gitlab.logicmoo.org:3100/ctl/
#ProxyPassReverse /ws/ http://gitlab.logicmoo.org:3100/ws/
ProxyPass /local.js http://gitlab.logicmoo.org:3100/local.js
ProxyPass /port3100 http://gitlab.logicmoo.org:3100
ProxyPassReverse /port3100 http://gitlab.logicmoo.org:3100
ProxyPassReverse /static/ http://gitlab.logicmoo.org:3020/static/

ProxyPass /port3101 http://gitlab.logicmoo.org:3101
ProxyPassReverse /port3101/ http://gitlab.logicmoo.org:3101/

ProxyPass /port3123 http://gitlab.logicmoo.org:3123
ProxyPassReverse /port3123/ http://gitlab.logicmoo.org:3123/


ProxyPass /help http://gitlab.logicmoo.org:3020/help
ProxyPass /js http://gitlab.logicmoo.org:3020/js
ProxyPass /css http://gitlab.logicmoo.org:3020/css
ProxyPass /logicmoo/ http://gitlab.logicmoo.org:3020/logicmoo/
ProxyPass /e/ http://gitlab.logicmoo.org:3020/e/
ProxyPass /pengine http://gitlab.logicmoo.org:3020/pengine
ProxyPass /icons http://gitlab.logicmoo.org:3020/icons
ProxyPass /home/ http://gitlab.logicmoo.org:3020/home
ProxyPass /home http://gitlab.logicmoo.org:3020/home
ProxyPass /login http://gitlab.logicmoo.org:3020/login
ProxyPass /static http://gitlab.logicmoo.org:3020/static


ProxyPass /dashboard http://gitlab.logicmoo.org:3020/dashboard
ProxyPass /users http://gitlab.logicmoo.org:3020/users
ProxyPass /user http://gitlab.logicmoo.org:3020/user
ProxyPass /prologmud http://gitlab.logicmoo.org:3020/prologmud
ProxyPass /assets http://gitlab.logicmoo.org:3020/assets
ProxyPass /openid http://gitlab.logicmoo.org:3020/openid
ProxyPass /flint http://gitlab.logicmoo.org:3020/flint
ProxyPass /yasgui http://gitlab.logicmoo.org:3020/yasgui
ProxyPass /cpack http://gitlab.logicmoo.org:3020/cpack
ProxyPass /sparql http://gitlab.logicmoo.org:3020/sparql
ProxyPass /swish http://gitlab.logicmoo.org:3020/swish
ProxyPass /filesystem http://gitlab.logicmoo.org:3020/filesystem



RewriteCond   "$1.php"           -f
RewriteCond   "$1.html"          !-f
RewriteRule   "^(.*).html$"      "$1.php"

RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{REQUEST_URI} ^/downloads.* [OR]
RewriteCond %{REQUEST_URI} ^/index.*$ [OR]
RewriteCond %{REQUEST_URI} ^/welcome.*$ [OR]
RewriteCond %{DOCUMENT_ROOT}/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/$1 -d [OR]
RewriteCond %{DOCUMENT_ROOT}/$1 -l 
RewriteRule (.*) - [S,L]



ProxyPassReverse "/" "http://gitlab.logicmoo.org:3020/
ProxyPassReverse "/" "http://logicmoo.org:3020/



#RewriteCond %{HTTP_HOST} !^gitlab\.logicmoo\.org$
#RewriteRule ^(.*)$ "http\:\/\/gitlab\.logicmoo\.org\/" [R=302]


# RewriteCond %{HTTP:Connection} Upgrade [NC]
# RewriteCond %{HTTP:Upgrade} websocket [NC]
# RewriteRule /(.*) ws://gitlab.logicmoo.org:3020/$1 [P,L]
#RewriteLog /var/log/apache/server2.rewrite.log
#RewriteLogLevel 4
LogLevel alert rewrite:trace3

#RewriteRule /jhub/(.*) ws://gitlab.logicmoo.org:8000/$1 [P,L]
#RewriteRule /jhub/(.*) http://gitlab.logicmoo.org:8000/$1 [P,L] 
#ProxyPass /jhub/ http://gitlab.logicmoo.org:8000/
#ProxyPassReverse /jhub/  http://gitlab.logicmoo.org:8000/


RewriteCond %{REQUEST_URI} !^/3020.*
RewriteCond %{REQUEST_URI} !^/port.*
RewriteCond %{REQUEST_URI} !^/stat.*
RewriteCond %{REQUEST_URI} !^/butt.*
RewriteCond %{REQUEST_URI} !^/local.js
RewriteCond %{REQUEST_URI} !^/ctl.*
RewriteCond %{REQUEST_URI} !^/ws.*
RewriteCond %{REQUEST_URI} !^/ef.*
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^.*/index.*$
RewriteCond %{REQUEST_URI} !^.*/welcome.*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l  
RewriteRule "^/(.*)" "http://gitlab.logicmoo.org:3020/$1" [P,L]
# ProxyPassReverse "/" "http://gitlab.logicmoo.org:3020/

</VirtualHost>
</IfModule>
