<virtualhost *:80>	
	<Directory "/var/www/localhost/public_html">
		AllowOverride All
		Options -Indexes -FollowSymLinks
		Require all granted
	</Directory>
	
ErrorLog /var/log/re3gistry-int_error_log
CustomLog /var/log/re3gistry-int_access_log combined

#### Basic configuration ###
#
#Alias /registry /var/www/registry
#Alias /registry/release-note.xml /var/www/localhost/public_html/release-note.xml
Alias /registry /var/www/localhost/htdocs
    
DirectoryIndex index.html

DocumentRoot /var/www/localhost/htdocs
#DocumentRoot /var/www/empty

ProxyPreserveHost Off

## SSLProxyEngine on
# SSLProxyEngine On
# SSLProxyCheckPeerCN on
# SSLProxyCheckPeerExpire on

## Proxy to expose the Re2gistry 2 management interface
ProxyPass /re3gistry2 http://localhost:8080/re3gistry2
ProxyPassReverse /re3gistry2 http://localhost:8080/re3gistry2

## Proxy to expose the Re2gistry 2 rest API
ProxyPass /registry/rest http://localhost:8080/re3gistry2restapi/items/any Keepalive=On
ProxyPassReverse  /registry/rest http://localhost:8080/re3gistry2restapi/items/any Keepalive=On

## Proxypass to expose the Re3gistry 2 Solr instance (select)
ProxyPass /registry/searchapi http://localhost:8983/solr/re3gistry/select Keepalive=On
ProxyPassReverse /registry/searchapi http://localhost:8983/solr/re3gistry/select Keepalive=On

### Rewrite rules ###
RewriteEngine on
loglevel debug rewrite:trace3

## Handling direct request to a file
RewriteCond %{REQUEST_URI} !^/registry/js-ecl-v2
RewriteRule ^/(.*)/(.*)\.([a-z]{2})\.(jsonc|json|xml|atom|csv|rdf|iso19135xml|ror)$ %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=$3&uri=http://%{HTTP_HOST}/$1&format=$4 [P,L]

#Handling dynamic XSD
RewriteCond %{REQUEST_URI} ^/registry/schemas/2.0
RewriteRule ^/registry/schemas/2.0/(.*)\.xsd$ %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?itemclass=$1&format=xsd [P,L]


## Handling content negotiation: json
RewriteCond %{REQUEST_URI} !^/registry/rest
RewriteCond %{HTTP_ACCEPT}  ^application/json$
RewriteCond %{HTTP:Accept-Language} ([a-z]{2}) [OR]
RewriteCond %{HTTP:Accept-Language} ^()$
RewriteRule ^/(.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=%1&uri=http://%{HTTP_HOST}/$1&format=json [P,L]

## Handling content negotiation: iso19135xml
RewriteCond %{REQUEST_URI} !^/registry/rest
RewriteCond %{HTTP_ACCEPT}  ^application/x-iso19135+xml$
RewriteCond %{HTTP:Accept-Language} ([a-z]{2}) [OR]
RewriteCond %{HTTP:Accept-Language} ^()$
RewriteRule ^/(.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=%1&uri=http://%{HTTP_HOST}/$1&format=iso19135xml [P,L]

## Handling content negotiation: re3gistry xml
RewriteCond %{REQUEST_URI} !^/registry/rest
RewriteCond %{HTTP_ACCEPT}  ^application/xml$
RewriteCond %{HTTP:Accept-Language} ([a-z]{2}) [OR]
RewriteCond %{HTTP:Accept-Language} ^()$
RewriteRule ^/(.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=%1&uri=http://%{HTTP_HOST}/$1&format=xml [P,L]

## Handling content negotiation: atom
RewriteCond %{REQUEST_URI} !^/registry/rest
RewriteCond %{HTTP_ACCEPT}  ^application/atom+xml$
RewriteCond %{HTTP:Accept-Language} ([a-z]{2}) [OR]
RewriteCond %{HTTP:Accept-Language} ^()$
RewriteRule ^/(.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=%1&uri=http://%{HTTP_HOST}/$1&format=atom [P,L]

## Handling content negotiation: atom
RewriteCond %{REQUEST_URI} !^/registry/rest
RewriteCond %{HTTP_ACCEPT}  ^application/rdf+xml$
RewriteCond %{HTTP:Accept-Language} ([a-z]{2}) [OR]
RewriteCond %{HTTP:Accept-Language} ^()$
RewriteRule ^/(.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=%1&uri=http://%{HTTP_HOST}/$1&format=rdf [P,L]

## Handling content negotiation: atom
RewriteCond %{REQUEST_URI} !^/registry/rest
RewriteCond %{HTTP_ACCEPT}  ^text/csv$
RewriteCond %{HTTP:Accept-Language} ([a-z]{2}) [OR]
RewriteCond %{HTTP:Accept-Language} ^()$
RewriteRule ^/(.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=%1&uri=http://%{HTTP_HOST}/$1&format=csv [P,L]

#Handling ROR format without specific language (defaults to ENG)

RewriteRule ^/(.*)/((.*)\.(ror))$ %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?uri=http://%{HTTP_HOST}/$1&lang=en&format=ror [P,NE,L]

## Generic request to the registry
RewriteCond %{REQUEST_URI} !^/cache-all-reg
RewriteCond %{REQUEST_URI} !^/re3gistry
RewriteCond %{REQUEST_URI} !^/registry/searchapi
RewriteCond %{REQUEST_URI} !^/registry/search
RewriteCond %{REQUEST_URI} !^/registry/rest
RewriteCond %{REQUEST_URI} !^/registry/index\.html
RewriteCond %{REQUEST_URI} !^/registry/about\.html
RewriteCond %{REQUEST_URI} !^/registry/api\.html
RewriteCond %{REQUEST_URI} !^/registry/release-note\.xml
RewriteCond %{REQUEST_URI} !^/registry/js-ecl-v2
RewriteCond %{REQUEST_URI} !^/registry/ecl-v2
RewriteCond %{REQUEST_URI} !^/registry/css
RewriteCond %{REQUEST_URI} !^/registry/conf
RewriteCond %{REQUEST_URI} !^/registry/libs
RewriteCond %{REQUEST_URI} !index\.html$
RewriteCond %{REQUEST_URI} !\.json$
RewriteRule ^/(.*) /index.html [L]

     
## Handling search requests
RewriteCond %{REQUEST_URI} !^/registry/searchapi
RewriteRule ^/registry/search(.*) /search.html$1 [L]

<Location /registry/release-note.xml>
  Header set Cache-Control "no-cache, no-store, must-revalidate, s-max-age=1"
  Header set Pragma        "no-cache"
  Header set Expires       "Sat, 1 Jan 2000 00:00:00 GMT"
</Location>

</virtualhost>
