[mapserver-users] Correct Mod Rewrite rule

Trond Michelsen trondmm-mapserver+2017 at crusaders.no
Mon Jun 13 03:40:22 PDT 2022


You have to add the Rewrite-flag QSA (query string append). Otherwise,
the query string from the incoming request is lost. There's also no
need to try to match the query string in your pattern. 

So, try this instead:

RewriteRule wms /cgi-bin/mapserv?map=/usr/share/mapserv/mapfile.map [QSA]

On Mon, Jun 13, 2022 at 10:28:02AM +0100, Paul Lewis wrote:
> I Want to change this:
> 
> 
> *https://<our server>/cgi-bin/mapserv?map=/usr/share/mapserv/mapfile.map&service=wms&version=1.3.0&request=GetCapabilities*
> 
> To this:
> 
> *https://<our server>/wms?service=WMS&version=1.3.0&request=GetCapabilities*
> 
> So I've enabled apache2 mod-rewrite and created a .htaccess file
> with the following rule as per Mapserver docs:
> 
> *RewriteEngine on**
> **RewriteRule wms?(.*)
> /cgi-bin/mapserv?map=/usr/share/mapserv/mapfile.map&$1**
> *
> I've also adapted this rule to numerous variations to try and get it
> working but to no avail.
> The first link returns xml as expected.
> The second link returns this error:
> 
> *mapserv(): Web application error. Traditional BROWSE mode requires
> a TEMPLATE in the WEB section, but none was provided.*
> 
> I've an error log running for the rewrite with an example trace as follows:
> 
> 
> *[Thu Jun 09 18:54:22.033848 2022] [rewrite:trace3] [pid 40275:tid
> 140188000974592] mod_rewrite.c(483): [client <browser IP>:62351]
> <browser IP> - - [<our
> server>/sid#7f80151c0340][rid#7f80147130a0/initial] [perdir
> /var/www/html/] strip per-dir prefix: /var/www/html/wms -> wms**
> **[Thu Jun 09 18:54:22.033855 2022] [rewrite:trace3] [pid 40275:tid
> 140188000974592] mod_rewrite.c(483): [client <browser IP>:62351]
> <browser IP> - - [<our
> server>/sid#7f80151c0340][rid#7f80147130a0/initial] [perdir
> /var/www/html/] applying pattern 'wms?(.*)' to uri 'wms'**
> **[Thu Jun 09 18:54:22.033864 2022] [rewrite:trace2] [pid 40275:tid
> 140188000974592] mod_rewrite.c(483): [client <browser IP>:62351]
> <browser IP> - - [<our
> server>/sid#7f80151c0340][rid#7f80147130a0/initial] [perdir
> /var/www/html/] rewrite 'wms' ->
> '/cgi-bin/mapserv?map=/usr/share/mapserv/gni_wms.map&'**
> **[Thu Jun 09 18:54:22.033870 2022] [rewrite:trace3] [pid 40275:tid
> 140188000974592] mod_rewrite.c(483): [client <browser IP>:62351]
> <browser IP> - - [<our
> server>/sid#7f80151c0340][rid#7f80147130a0/initial] split
> uri=/cgi-bin/mapserv?map=/usr/share/mapserv/gni_wms.map& ->
> uri=/cgi-bin/mapserv, args=map=/usr/share/mapserv/gni_wms.map**
> **[Thu Jun 09 18:54:22.033877 2022] [rewrite:trace2] [pid 40275:tid
> 140188000974592] mod_rewrite.c(483): [client <browser IP>:62351]
> <browser IP> - - [<our
> server>/sid#7f80151c0340][rid#7f80147130a0/initial] [perdir
> /var/www/html/] trying to replace context docroot /var/www/html with
> context prefix**
> **[Thu Jun 09 18:54:22.033883 2022] [rewrite:trace1] [pid 40275:tid
> 140188000974592] mod_rewrite.c(483): [client <browser IP>:62351]
> <browser IP> - - [<our
> server>/sid#7f80151c0340][rid#7f80147130a0/initial] [perdir
> /var/www/html/] internal redirect with /cgi-bin/mapserv [INTERNAL
> REDIRECT]**
> *
> 
> 
> Am I correct in thinking that the redirect is not handling the GET params?
> 
> Which means my rule is wrong and is hence passing the wrong request
> string to mapserver thus causing the error?
> 
> 
> Paul

> _______________________________________________
> MapServer-users mailing list
> MapServer-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/mapserver-users


-- 
Trond Michelsen


More information about the MapServer-users mailing list