[mapserver-users] Rewrite rule problem

Eichner, Andreas - SID Andreas.Eichner at sid.sachsen.de
Thu Nov 2 03:14:26 PDT 2017


Hi Goran,

using a path segment to fill in a query parameter is pretty straight forward but the following assumes MapServer is installed under /cgi-bin/GDZ/wms:

  RewriteEngine On
  RewriteRule ^/cgi-bin/GDZ/([^/]+)/wms$ /cgi-bin/GDZ/wms?MAP=MS_MAPFILE&year=$1 [PT,QSA]

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

If you have MapServer-CGI installed as "/cgi-bin/mapserv" you better abstain from using SetEnvIfExpr and do with plain rewriting:

  RewriteEngine On
  RewriteCond %{QUERY_STRING} "^(.*&)?map=([[:alnum:]]+.map)(&.*)?$" [NC]
  RewriteRule ^/cgi-bin/GDZ/([^/]+)/wms$ /cgi-bin/mapserv?MAP=MS_MAPFILE&year=$1 [PT,QSA,E=MS_MAPFILE:C:/ms4w/apps/Demo/%2]

The basic question is: what are you trying to achieve? What's the reason to deal with the MAP parameter?
For WMS services you normally want plain URLs like "/wms/GDZ/2017?<query>" be rewritten 
to "/cgi-bin/mapserv?MAP=GDZ.map&year=2017&<query>" which could expressed by a really simple RewriteRule:

  RewriteEngine On
  RewriteRule "^/wms/([[:alnunm]]+)/([^/]+)$" /cgi-bin/mapserv?MAP=C:/ms4w/apps/Demo/$1.map&year=$2 [PT,QSA]

HTH

> -----Ursprüngliche Nachricht-----
> Von: mapserver-users [mailto:mapserver-users-bounces at lists.osgeo.org] Im
> Auftrag von gorank
> Gesendet: Mittwoch, 1. November 2017 23:13
> An: mapserver-users at lists.osgeo.org
> Betreff: Re: [mapserver-users] Rewrite rule problem
> 
> Hi Andreas,
> 
> Finally it works perfectly and it solved most of my problems.  I would
> like
> to go one step forward. How will looks   SetEnvIfExpr and Rewrite rule
> in
> case when in the mapfile there is a Real time substitution parameter (in
> my
> case year - 2015, 2016, ...)
> I would like to write url as you proposed in previous post but with
> added
> year parameter. Example for year 2015:
> from
> http://localhost:81/cgi-
> bin/GDZ/2015/wms?map=N1.map&REQUEST=GetCapabilities&SERVICE=WMS&VERSION=
> 1.3.0
> 
> to get
> 
> http://localhost:81/cgi-
> bin/GDZ/wms?year=2015&map=N1.map&REQUEST=GetCapabilities&SERVICE=WMS&VER
> SION=1.3.0
> 
> I tried to do it following your logic but not successfully.
> 
> 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