Hiding the map= parameter from a map server application

In the mapserver documentation, one is told to use a cgi-wrapper script to hide the map= parameter. Then there is shown a script to use on ‘any system having a /bin/sh’ I tried to rewrite that as a php-script to use under windows, but that did not work, so apaches mod_rewrite to the rescue in four small steps:

  1. make sure the mod_rewrite is enabled in httpd.conf. Usually it is commented out by default, if necessary remove the comment sign.
  2. Enable mod_rewrite for the actual document root. I am using virtual servers and added the following lines in the actual <VirtualHost > section:

    <Directory “c:\documents and settings\vserver\radioecology”>
    Options FollowSymLinks
    AllowOverride All
    </Directory>

  3. Restart apache
  4. make a .htaccess file in the actual directory:

    RewriteEngine on
    RewriteRule ^wmsmap?(.*) /cgi-bin/mapserv.exe?map=/documents+and+settings/vserver/radioecology/mobilweb/mobilwms.map&$1

    (Everything following RewriteRule must be on one line. in this case, the map file I want to pull in is “/documents+and+settings/vserver/radioecology/mobilweb/mobilwms.map” adjust as needed for your application.)

    The rewriteRule says: given a webpage starting with wmsmap, pick out the query parameters, make a new page request starting with /cgi-bin/mapserv.exe?map=(…)? and add on whatever was the query parameter in the original page request. Quite simple when one just knows how to do it.

This entry was posted in Diverse, mapserver. Bookmark the permalink.