Re: [mapserver-users] Rewrite rule problem
Hi, It works. Many thanks. Sorry, I was absent in this this period and I couldn't reply. Best regards, Goran -- Sent from: http://osgeo-org.1560.x6.nabble.com/Mapserver-User-f4226646.html ___ mapserver-users mailing list mapserver-users@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] Rewrite rule problem
Damn, the last RewriteRule should be RewriteEngine On RewriteRule "^/wms/([[:alnum:]]+)/([[:digit:]]+)$" /cgi-bin/mapserv?MAP=C:/ms4w/apps/Demo/$1.map=$2 [PT,QSA] The character classes prevent bad file names and value for the "year" parameter. You should set up a proper validation for the year and/or MS_MAP_PATTERN too. Sorry for the noise ___ mapserver-users mailing list mapserver-users@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] Rewrite rule problem
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=$1 [PT,QSA] SetEnvIfExpr "%{QUERY_STRING} =~ /^(.*&)?map=([[:alnum:]]+.map)(&.*)?$/" MS_MAPFILE=C:/ms4w/apps/Demo/$2 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=$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?" be rewritten to "/cgi-bin/mapserv?MAP=GDZ.map=2017&" which could expressed by a really simple RewriteRule: RewriteEngine On RewriteRule "^/wms/([[:alnunm]]+)/([^/]+)$" /cgi-bin/mapserv?MAP=C:/ms4w/apps/Demo/$1.map=$2 [PT,QSA] HTH > -Ursprüngliche Nachricht- > Von: mapserver-users [mailto:mapserver-users-boun...@lists.osgeo.org] Im > Auftrag von gorank > Gesendet: Mittwoch, 1. November 2017 23:13 > An: mapserver-users@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=GetCapabilities=WMS= > 1.3.0 > > to get > > http://localhost:81/cgi- > bin/GDZ/wms?year=2015=N1.map=GetCapabilities=WMS > 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@lists.osgeo.org > https://lists.osgeo.org/mailman/listinfo/mapserver-users ___ mapserver-users mailing list mapserver-users@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] Rewrite rule problem
Goran, for good Open Source karma would you mind recording and publishing all of your steps, to get MS4W and Apache to do the rewriting you need? You can add the new page on the MapServer wiki (https://github.com/mapserver/mapserver/wiki) or even directly on the MS4W wiki (https://www.ms4w.com/trac/wiki), whatever is easiest for you. A huge thank you for that. -jeff -- Jeff McKenna MapServer Consulting and Training Services http://www.gatewaygeomatics.com/ On 2017-11-01 7:12 PM, gorank wrote: 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=GetCapabilities=WMS=1.3.0 to get http://localhost:81/cgi-bin/GDZ/wms?year=2015=N1.map=GetCapabilities=WMS=1.3.0 I tried to do it following your logic but not successfully. Best regards, Goran ___ mapserver-users mailing list mapserver-users@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/mapserver-users
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=GetCapabilities=WMS=1.3.0 to get http://localhost:81/cgi-bin/GDZ/wms?year=2015=N1.map=GetCapabilities=WMS=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@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] Rewrite rule problem
Hi Goran, the RewriteRule should match the Location for SetEnvIfExpr: SetEnvIfExpr "%{QUERY_STRING} =~/^(.*&)?map=([[:alnum:]]+.map)(&.*)?$/" MS_MAPFILE=C:/ms4w/apps/Demo/$2 RewriteEngine On RewriteRule /cgi-bin/GDZ/wms /cgi-bin/GDZ/wms?MAP=MS_MAPFILE [PT,QSA] And then the URL http://localhost:81/cgi-bin/GDZ/wms?map=N1.map=GetCapabilities=WMS=1.3.0 should set the MS_MAPFILE environment variable to "C:/ms4w/apps/Demo/N1.map" and rewrite the URL to http://localhost:81/cgi-bin/GDZ/wms?MAP=MS_MAPFILE=N1.map=GetCapabilities=WMS=1.3.0 This should work as MapServer scans the query parameters from left to right. It first finds MAP=MS_MAPFILE and checks if there's an environment variable set assuming that it points to a valid map file. The SetEnvIfExpr has set this variable for the URL "/cgi-bin/GDZ/wms" if a "MAP" parameter was provided. HTH > -Ursprüngliche Nachricht- > Von: mapserver-users [mailto:mapserver-users-boun...@lists.osgeo.org] Im > Auftrag von gorank > Gesendet: Montag, 30. Oktober 2017 16:24 > An: mapserver-users@lists.osgeo.org > Betreff: Re: [mapserver-users] Rewrite rule problem > > Hi Andreas, > > As you sugested I have added in* httpd.conf* file following > > > and when I put URL > > I receive the following message: > msLoadMap(): Unable to access file. (N1.map) > > As addition in the C:/ms4w/httpd.d folder I have file httpd_Demo.conf > file > with following content > > Alias /Demo/ "/ms4w/apps/Demo/" > > AllowOverride None > Options Indexes FollowSymLinks Multiviews > Order allow,deny > Allow from all > > > What I'm doing wrong. > > Best regards, > Goran > > > > -- > Sent from: http://osgeo-org.1560.x6.nabble.com/Mapserver-User- > f4226646.html > ___ > mapserver-users mailing list > mapserver-users@lists.osgeo.org > https://lists.osgeo.org/mailman/listinfo/mapserver-users ___ mapserver-users mailing list mapserver-users@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] Rewrite rule problem
Hi Andreas, As you sugested I have added in* httpd.conf* file following SetEnvIfExpr "%{QUERY_STRING} =~ /^(.*&)?map=([[:alnum:]]+.map)(&.*)?$/" MS_MAPFILE=C:/ms4w/apps/Demo/$2 RewriteRule /cgi-bin/Demo/wms /cgi-bin/Demo/wms?MAP=MS_MAPFILE [PT,QSA] and when I put URL http://localhost:81/cgi-bin/Demo/wms?map=N1.map=GetCapabilities=WMS=1.3.0 I receive the following message: msLoadMap(): Unable to access file. (N1.map) As addition in the C:/ms4w/httpd.d folder I have file httpd_Demo.conf file with following content Alias /Demo/ "/ms4w/apps/Demo/" AllowOverride None Options Indexes FollowSymLinks Multiviews Order allow,deny Allow from all What I'm doing wrong. Best regards, Goran -- Sent from: http://osgeo-org.1560.x6.nabble.com/Mapserver-User-f4226646.html ___ mapserver-users mailing list mapserver-users@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] Rewrite rule problem
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 block to do this only for a specific URI: SetEnvIfExpr "%{QUERY_STRING} =~ /^(.*&)?map=([[:alnum:]]+.map)(&.*)?$/" MS_MAPFILE=C:/ms4w/apps/Demo/$2 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=GetCapabilities Needs to be written as /cgi-bin/Demo/wms?map=MS_MAPFILE=N1.map=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-boun...@lists.osgeo.org] Im > Auftrag von gorank > Gesendet: Samstag, 28. Oktober 2017 16:55 > An: mapserver-users@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=WMS=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*=GetCapabilities=WMS=1. > 3.0 > for first mapfile and > http://localhost:81/cgi- > bin/Demo/wms?*map=N2.map*=GetCapabilities=WMS=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@lists.osgeo.org > https://lists.osgeo.org/mailman/listinfo/mapserver-users ___ mapserver-users mailing list mapserver-users@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/mapserver-users
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=WMS=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*=GetCapabilities=WMS=1.3.0 for first mapfile and http://localhost:81/cgi-bin/Demo/wms?*map=N2.map*=GetCapabilities=WMS=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@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] Rewrite rule problem
Note that my steps should give you the url http://localhost/cgi-bin/wms? -jeff -- Jeff McKenna MapServer Consulting and Training Services http://www.gatewaygeomatics.com/ On 2017-10-26 3:22 PM, Jeff McKenna wrote: Hi Goran, Regarding have a cleaner WMS url inside your MS4W installation, you can follow the steps at http://mapserver.org/ogc/wms_server.html#changing-the-online-resource-url So that means, if you wanted a clean url like http://localhost/cgi-bin/Demo/wms? you could: - rename /ms4w/Apache/cgi-bin/mapserv.exe to /ms4w/Apache/cgi-bin/wms (no extension) - edit /ms4w/Apache/conf/httpd.conf and add at the bottom something like SetEnvIf Request_URI "/cgi-bin/wms" MS_MAPFILE=C:/ms4w/apps/mymap.map - restart Apache service apache-restart.bat Hope that helps. -jeff -- Jeff McKenna MapServer Consulting and Training Services http://www.gatewaygeomatics.com/ On 2017-10-21 4:31 AM, gorank wrote: I would like to use Rewrite rules to change path to the map file in the URL with mapfile name only. Example: http://localhost:81/cgi-bin/Demo/wms?map=*/ms4w/apps/Demo/N1.map*=GetCapabilities=WMS=1.3.0 for users to be http://localhost:81/cgi-bin/Demo/wms?map=*N1.map*=GetCapabilities=WMS=1.3.0 I have tried different sugestions in mapserver documenation but it doesn't work. I need help somebody to describe step by step: 1. Where should be located the new created .htaccess file (Rewrite mode in the httpd.conf file is activated - without #) . In the httpd.conf file Document Root is # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "C:/ms4w/Apache/htdocs" AccessFileName .htaccess 2. What should be written in the .htaccess file in my case 3. If i have different Rewrite rules for different paths how to separate them in the .htaccess file Best Regards, Goran ___ mapserver-users mailing list mapserver-users@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] Rewrite rule problem
Hi Goran, Regarding have a cleaner WMS url inside your MS4W installation, you can follow the steps at http://mapserver.org/ogc/wms_server.html#changing-the-online-resource-url So that means, if you wanted a clean url like http://localhost/cgi-bin/Demo/wms? you could: - rename /ms4w/Apache/cgi-bin/mapserv.exe to /ms4w/Apache/cgi-bin/wms (no extension) - edit /ms4w/Apache/conf/httpd.conf and add at the bottom something like SetEnvIf Request_URI "/cgi-bin/wms" MS_MAPFILE=C:/ms4w/apps/mymap.map - restart Apache service apache-restart.bat Hope that helps. -jeff -- Jeff McKenna MapServer Consulting and Training Services http://www.gatewaygeomatics.com/ On 2017-10-21 4:31 AM, gorank wrote: I would like to use Rewrite rules to change path to the map file in the URL with mapfile name only. Example: http://localhost:81/cgi-bin/Demo/wms?map=*/ms4w/apps/Demo/N1.map*=GetCapabilities=WMS=1.3.0 for users to be http://localhost:81/cgi-bin/Demo/wms?map=*N1.map*=GetCapabilities=WMS=1.3.0 I have tried different sugestions in mapserver documenation but it doesn't work. I need help somebody to describe step by step: 1. Where should be located the new created .htaccess file (Rewrite mode in the httpd.conf file is activated - without #) . In the httpd.conf file Document Root is # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "C:/ms4w/Apache/htdocs" AccessFileName .htaccess 2. What should be written in the .htaccess file in my case 3. If i have different Rewrite rules for different paths how to separate them in the .htaccess file Best Regards, Goran ___ mapserver-users mailing list mapserver-users@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] Rewrite rule problem
No sugestions??? Best regards. Goran -- Sent from: http://osgeo-org.1560.x6.nabble.com/Mapserver-User-f4226646.html ___ mapserver-users mailing list mapserver-users@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/mapserver-users
[mapserver-users] Rewrite rule problem
I would like to use Rewrite rules to change path to the map file in the URL with mapfile name only. Example: http://localhost:81/cgi-bin/Demo/wms?map=*/ms4w/apps/Demo/N1.map*=GetCapabilities=WMS=1.3.0 for users to be http://localhost:81/cgi-bin/Demo/wms?map=*N1.map*=GetCapabilities=WMS=1.3.0 I have tried different sugestions in mapserver documenation but it doesn't work. I need help somebody to describe step by step: 1. Where should be located the new created .htaccess file (Rewrite mode in the httpd.conf file is activated - without #) . In the httpd.conf file Document Root is # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "C:/ms4w/Apache/htdocs" AccessFileName .htaccess 2. What should be written in the .htaccess file in my case 3. If i have different Rewrite rules for different paths how to separate them in the .htaccess file Best Regards, Goran -- Sent from: http://osgeo-org.1560.x6.nabble.com/Mapserver-User-f4226646.html ___ mapserver-users mailing list mapserver-users@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/mapserver-users