1 # Setting up the Nominatim UI
 
   3 Nominatim is a search API, it does not provide a website interface on its
 
   4 own. [nominatim-ui](https://github.com/osm-search/nominatim-ui) offers a
 
   5 small website for testing your setup and inspecting the database content.
 
   7 This section provides a quick start how to use nominatim-ui with your
 
   8 installation. For more details, please also have a look at the
 
   9 [README of nominatim-ui](https://github.com/osm-search/nominatim-ui/blob/master/README.md).
 
  11 ## Installing nominatim-ui
 
  13 nominatim-ui does not need any special installation, just download, configure
 
  16 Clone the source from github:
 
  18     git clone https://github.com/osm-search/nominatim-ui
 
  20 Copy the example configuration into the right place:
 
  23     cp dist/config.example.js dist/config.js
 
  25 Now adapt the configuration to your needs. You need at least
 
  26 to change the `Nominatim_API_Endpoint` to point to your Nominatim installation.
 
  28 Then you can just test it locally by spinning up a webserver in the `dist`
 
  29 directory. For example, with Python:
 
  32     python3 -m http.server 8765
 
  34 The website is now available at `http://localhost:8765`.
 
  36 ## Forwarding searches to nominatim-ui
 
  38 Nominatim used to provide the search interface directly by itself when
 
  39 `format=html` was requested. For all endpoints except for `/reverse` and
 
  40 `/lookup` this even used to be the default.
 
  42 The following section describes how to set up Apache or nginx, so that your
 
  43 users are forwarded to nominatim-ui when they go to URL that formerly presented
 
  46 ### Setting up forwarding in Nginx
 
  48 First of all make nominatim-ui available under `/ui` on your webserver:
 
  53     # Here is the Nominatim setup as described in the Installation section
 
  56         alias <full path to the nominatim-ui directory>/dist/;
 
  62 Now we need to find out if a URL should be forwarded to the UI. Add the
 
  63 following `map` commands *outside* the server section:
 
  66 # Inspect the format parameter in the query arguments. We are interested
 
  67 # if it is set to html or something else or if it is missing completely.
 
  70     ~(^|&)format=html(&|$)   html;
 
  74 # Determine from the URI and the format parameter above if forwarding is needed.
 
  75 map $uri/$format $forward_to_ui {
 
  76     default               1;   # The default is to forward.
 
  77     ~^/ui                 0;   # If the URI point to the UI already, we are done.
 
  78     ~/other$              0;   # An explicit non-html format parameter. No forwarding.
 
  79     ~/reverse.*/default   0;   # Reverse and lookup assume xml format when
 
  80     ~/lookup.*/default    0;   #   no format parameter is given. No forwarding.
 
  84 The `$forward_to_ui` parameter can now be used to conditionally forward the
 
  88 # When no endpoint is given, default to search.
 
  89 # Need to add a rewrite so that the rewrite rules below catch it correctly.
 
  95         rewrite ^(/[^/]*) https://yourserver.com/ui$1.html redirect;
 
  99 location ~ [^/]\.php(/|$) {
 
 101     if ($forward_to_ui) {
 
 102         rewrite (.*).php https://yourserver.com/ui$1.html redirect;
 
 108     Be aware that the rewrite commands are slightly different for URIs with and
 
 109     without the .php suffix.
 
 111 Reload nginx and the UI should be available.
 
 113 ### Setting up forwarding in Apache
 
 115 First of all make nominatim-ui available in the `ui/` subdirectory where
 
 116 Nominatim is installed. For example, given you have set up an alias under
 
 117 `nominatim` like this:
 
 120 Alias /nominatim /home/vagrant/build/website
 
 123 you need to insert the following rules for nominatim-ui before that alias:
 
 126 <Directory "/home/vagrant/nominatim-ui/dist">
 
 127   DirectoryIndex search.html
 
 131 Alias /nominatim/ui /home/vagrant/nominatim-ui/dist
 
 134 Replace `/home/vagrant/nominatim-ui` with the directory where you have cloned
 
 138     The alias for nominatim-ui must come before the alias for the Nominatim
 
 141 To set up forwarding, the Apache rewrite module is needed. Enable it with:
 
 147 Then add rewrite rules to the `Directory` directive of the Nominatim website
 
 151 <Directory "/home/vagrant/build/website">
 
 152   Options FollowSymLinks MultiViews
 
 153   AddType text/html   .php
 
 158   # This must correspond to the URL where nominatim can be found.
 
 159   RewriteBase "/nominatim/"
 
 161   # If no endpoint is given, then use search.
 
 162   RewriteRule ^(/|$)   "search.php"
 
 164   # If format-html is explicity requested, forward to the UI.
 
 165   RewriteCond %{QUERY_STRING} "format=html"
 
 166   RewriteRule ^([^/]+).php ui/$1.html [R,END]
 
 167   # Same but .php suffix is missing.
 
 168   RewriteCond %{QUERY_STRING} "format=html"
 
 169   RewriteRule ^([^/]+) ui/$1.html [R,END]
 
 171   # If no format parameter is there then forward anything
 
 172   # but /reverse and /lookup to the UI.
 
 173   RewriteCond %{QUERY_STRING} "!format="
 
 174   RewriteCond %{REQUEST_URI}  "!/lookup"
 
 175   RewriteCond %{REQUEST_URI}  "!/reverse"
 
 176   RewriteRule ^([^/]+).php ui/$1.html [R,END]
 
 177   # Same but .php suffix is missing.
 
 178   RewriteCond %{QUERY_STRING} "!format="
 
 179   RewriteCond %{REQUEST_URI}  "!/lookup"
 
 180   RewriteCond %{REQUEST_URI}  "!/reverse"
 
 181   RewriteRule ^([^/]+) ui/$1.html [R,END]
 
 185 Restart Apache and the UI should be available.