[mapserver-users] Rewrite rule problem

Eichner, Andreas - SID Andreas.Eichner at sid.sachsen.de
Mon Oct 30 04:32:23 PDT 2017


Hi,

I guess you should use SetEnvIfExpr to test the query string for 
the MAP parameter and set the environment variable using the value.
Wrap it into a <Location> block to do this only for a specific URI:

<Location "/cgi-bin/Demo/wms">
  SetEnvIfExpr "%{QUERY_STRING} =~ /^(.*&)?map=([[:alnum:]]+.map)(&.*)?$/" MS_MAPFILE=C:/ms4w/apps/Demo/$2
</Location>

IHMO this won't work though as MapServer's msCGILoadMap() function prefers the MAP param and uses the MS_MAPFILE environment variable only as a fallback.
As MS first checks if the MAP parameter points to the name of an environment variable containing the map file and scans the query parameters from left to right you can prepend a fake MAP parameter pointing to MS_MAPFILE.
For example a request to
  /cgi-bin/Demo/wms?map=N1.map&REQUEST=GetCapabilities
Needs to be written as
  /cgi-bin/Demo/wms?map=MS_MAPFILE&map=N1.map&REQUEST=GetCapabilities
You can do this using a RewriteRule like
  RewriteRule /cgi-bin/Demo/wms /cgi-bin/Demo/wms?MAP=MS_MAPFILE [PT,QSA]

HTH

> -----Ursprüngliche Nachricht-----
> Von: mapserver-users [mailto:mapserver-users-bounces at lists.osgeo.org] Im
> Auftrag von gorank
> Gesendet: Samstag, 28. Oktober 2017 16:55
> An: mapserver-users at lists.osgeo.org
> Betreff: Re: [mapserver-users] Rewrite rule problem
> 
> Hi Jeff,
> 
> Many thanks for your answer. I test it and works and solve my problem
> when
> have only one mapfile in the project. But when I have few mapfiles in
> the
> folder Demo under apps folder (C:/ms4w/apps/Demo) , how should look
> statement in SetEnvIf ?
> 
> When i try for different mapfiles
> 
> SetEnvIf Request_URI "/cgi-bin/Demo/wms"
> MS_MAPFILE=C:/ms4w/apps/Demo/N1.map
> SetEnvIf Request_URI "/cgi-bin/Demo/wms"
> MS_MAPFILE=C:/ms4w/apps/Demo/N2.map
> 
> the URL
> http://localhost:81/cgi-
> bin/Demo/wms?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.3.0
> opens XML for second mapfile - N2.map, and I suppose the second SetEnvIf
> statement overwrite the first one.
> 
> So, what is solution, in the URL to be included specific mapfile name,
> like
> http://localhost:81/cgi-
> bin/Demo/wms?*map=N1.map*&REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.
> 3.0
> for first mapfile and
> http://localhost:81/cgi-
> bin/Demo/wms?*map=N2.map*&REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.
> 3.0
> for second mapfile?
> 
> Best regards,
> Goran
> 
> 
> 
> --
> Sent from: http://osgeo-org.1560.x6.nabble.com/Mapserver-User-
> f4226646.html
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/mapserver-users


More information about the mapserver-users mailing list