Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe usage of mod_rewrite together with cgi wrapper script #3310

Closed
mapserver-bot opened this issue Apr 3, 2012 · 2 comments
Closed
Assignees

Comments

@mapserver-bot
Copy link

Reporter: mortensickel
Date: 2010/02/11 - 14:10
Trac URL: http://trac.osgeo.org/mapserver/ticket/3310
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 section of the httpd.conf insert:

<Directory |myhtdocsdir|>[BR]
AllowOverride All[BR]
[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[[BR]]
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.

@mapserver-bot
Copy link
Author

Author: tbonfort
Date: 2011/04/20 - 18:26
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>

@mapserver-bot
Copy link
Author

Author: havatv
Date: 2011/09/25 - 00:53
I have modified the explanation in wms_server using the suggestions in this ticket. Fixed for trunk and 6.0 in MapServer/MapServer-documentation@fbfa0f0 (r12585).

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

@ghost ghost assigned jmckenna Apr 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants