首页 > 解决方案 > 地图服务器包装 cgi-bin/mapserv 和 map=mapfile.map 的问题

问题描述

我正在使用 Mapserver 7.0.7 (MS4W 3.2.8),我无法包装 cgi-bin/mapserv 和 map=mapfile.map


工作正常

http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Leaflet/mapserver/Leaflet.map&service=WMS&request=GetMap&layers=LAT&styles=&format=image%2Fpng&transparent=true&version=1.3.0&tiled=true&width =512&height=512&crs=EPSG%3A3857&bbox=-6574807.424977722,-3443946.7464169012,-6261721.357121639,-3130860.67856082

结果


在.htaccess 中使用RewriteRule 进入我的leafletjs web 上的文件夹

RewriteRule ^ms(.*)$ http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Leaflet/mapserver/Leaflet.map $1

http://10.1.3.21/Leaflet/ms&service=WMS&request=GetMap&layers=LAT&styles=&format=image%2Fpng&transparent=true&version=1.3.0&tiled=true&width=512&height=512&crs=EPSG%3A3857&bbox=-6574807.424977722,-3443946.7464169012,-6261721.357121639,- 3130860.67856082

结果:

Not Found The requested URL /Leaflet/ms&service=WMS&request=GetMap&layers=LAT&styles=&format=image/png&transparent=true&version=1.3.0&tiled=true&width=512&height=512&crs=EPSG:3857&bbox=-6574807.424977722,-3443946.7464169012,-6261721.357121639,-3130860.67856082 was在此服务器上找不到。


但是是一个有效的 GetCapabilities 请求

http://localhost/Leaflet/ms&service=WMS&version=1.0.0&request=GetCapabilities

它被替换为 =>

http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Leaflet/mapserver/Leaflet.map&service=WMS&version=1.0.0&request=GetCapabilities

结果:

<!--  end of DOCTYPE declaration  -->
<WMT_MS_Capabilities version="1.0.0">
<!--
 MapServer version 7.0.7 (MS4W 3.2.8) OUTPUT=PNG OUTPUT=JPEG OUTPUT=KML SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=CAIRO SUPPORTS=SVG_SYMBOLS SUPPORTS=SVGCAIRO SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI SUPPORTS=THREADS SUPPORTS=GEOS SUPPORTS=POINT_Z_M INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE 
-->
<Service>
<Name>GetMap</Name>
<Title>Leaflet - WMS</Title>
<OnlineResource>http://localhost/Leaflet/ms?</OnlineResource>
</Service>
... 

标签: .htaccessurlmod-rewritewrappermapserver

解决方案


您的重写规则正在删除重要的?查询字符串字符,创建一个无效请求,/Leaflet/ms&service=WMS&... 但它应该导致/Leaflet/ms?service=WMS... 尝试如下规则:

RewriteRule ^ms?(.*)$ http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Leaflet/mapserver/Leaflet.map$1

推荐阅读