I am trying to use MapServer to display a raster image (png). That's it for now at least. However, I am having no luck. When I visit my map by using a link like:


I get the following error:

msLoadMap(): Regular expression error. MS_DEFAULT_MAPFILE_PATTERN validation failed. msEvalRegex(): Regular expression error. String failed expression test.

When I use shp2img:

shp2img -m file.map -o myimage.png -all_debug 5

I get no errors, but the image that's produced is completely gray except for the upper right quadrant which is white. This is nothing like my raster image.

My mapfile:

    SHAPEPATH     "/home/name/public_html/dir"
    EXTENT        -180 -90 180 90
    SIZE          800 600
    IMAGECOLOR    155 155 155
    UNITS         DD
    STATUS        ON
    DEBUG         ON

        NAME      "base"
        DATA      "/home/name/public_html/dir/image.png"
        STATUS    ON
        TYPE      RASTER

What am I doing wrong?


Your map file is fine.

I've seen the Regular expression error. MS_DEFAULT_MAPFILE_PATTERN validation failed error when the extension to the map file in the URL is incorrect e.g.

.map Works: http://myurl.com/cgi-bin/mapserv?map=/path/to/file.map&layer=base&mode=map

.map2 fails with above error: http://myurl.com/cgi-bin/mapserv?map=/path/to/file.map2&layer=base&mode=map

In the MapServer source code you can see the regular expression used to check for a valid mapfile (.xml is also now allowed):


If your path and mapfile are correctly defined then it must be something in your URL request. Do you have any URL rewriters active? Maybe try and look at the web server logs to see the exact URL it receives.

  • You're right, my url was wrong. However, I still have the problem that I'm getting a blank image using shp2img or the correct url. What could cause this? – peter Jun 26 '11 at 2:53
  • Ah! I figured it out, I think. A PNG raster must have a world file. – peter Jun 26 '11 at 3:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.