Opened 14 years ago

Closed 13 years ago

#3310 closed enhancement (fixed)

Describe usage of mod_rewrite together with cgi wrapper script

Reported by: mortensickel Owned by: jmckenna
Priority: normal Milestone:
Component: Documentation - MapServer Version: unspecified
Severity: normal Keywords:
Cc: tbonfort, havatv

Description

In the documentation, there is a description on how to make a cgi wrapper script and a script is given for "any OS with /bin/sh" for those of us running mapserv on an OS without /bin/sh, apache's mod_rewrite is the solution of choise. I would propose to add a subchapter on that as well. e.g. like:

=Using mod_rewrite =

==Introduction== This document presents how to use apache's mod_rewrite to be able not specify the map, or any other default parameter in your mapserver urls. This task consist of three steps, specifying the mod_rewrite module to be loaded, enabling the mod_rewrite module for the selected directories and at last to write a .htaccess file to do the rewriting

==Description== In the httpd.conf file, the mod_rewrite module is per default disabled. To enable it, remove the opening # in the line

#LoadModule rewrite_module modules/mod_rewrite.so

To be able to use the module, it must be enabled, using the directive AllowOverride. This can be done per server or per directory. If you just have one server, add an "AllowOverride All" line in the httpd.conf file (see the apache documentation to be sure about the security implications of this). Per directory is the easiest way to make it work on virtual hosts. Within the <virtualHost> section of the httpd.conf insert:

<Directory |myhtdocsdir|>[BR]

AllowOverride All[BR]

</Directory>[BR]

Where |myhtdocsdir| is the directory defined as documentroot for the actual virtual server.

When the directives are set to load and enable the mod_rewrite module, apache has to be restarted.

In a web-accessible directory make a .htaccess file like the following:

RewriteEngine on
RewriteRule wmsmap?(.*) /cgi-bin/mapserv?map=/home/www/mapserverstuff/mymapfile.map&$1

The rewriteRule says: given a webpage starting with wmsmap, pick out the query parameters, make a new page request starting with /cgi-bin/mapserv?map=(…)? and add on whatever was the query parameter in the original page request.

e.g, the url wmsmap?mode=map will be rewritten as /cgi-bin/mapserv?map=/home/www/mapserverstuff/mymapfile.map&mode=map

if just the url wmsmap is given (without any parameters) a page not found error will show up as that does not match the wmsmap? expression.

Change History (2)

comment:1 by tbonfort, 13 years ago

Cc: tbonfort added

We should not document the shell script as the default way of hiding the mapfile in requests, not only because of the absence of /bin/sh, but mostly because it causes an overhead on system resources as two processes have to be spawned instead of one.

there are other rewrite rules that can be used, along with the MS_MAPFILE environment variable

  • this one will rewrite all /wms/mymapfilename requests to /cgi-bin/mapserver?map=/datadir/mymapfilename.map
    RewriteRule ^/wms/(.*) /cgi-bin/mapserv?map=/datadir/$1.map [PT,QSA]
    
  • we can also use a default mapfile with:
    Alias /mywms /usr/lib/cgi-bin/mapserver
    <Location /mywms>
       SetHandler cgi-script
       Options ExecCGI
       SetEnv MS_MAPFILE /path/to/mymapfile.map
    </Location>
    

comment:2 by havatv, 13 years ago

Cc: havatv added
Resolution: fixed
Status: newclosed

I have modified the explanation in wms_server using the suggestions in this ticket. Fixed for trunk and 6.0 in r12585.

I think that it would be good to move the generic part of this section to another (separate?) document.

Note: See TracTickets for help on using tickets.