[mapserver-users] Correct Mod Rewrite rule

Paul Lewis paul.lewis at igeotec.com
Mon Jun 13 05:08:43 PDT 2022


Brilliant thank you, that has it sorted perfectly...

Paul

On 13/06/2022 11:40, Trond Michelsen wrote:
> 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
>

-- 
------------------------------------------------------------------------
*Paul Lewis PhD.*

*Chief Systems Architect*

iGeotech Technologies Limited (http://www.igeotec.com/) 
<http://www.igeotec.com/>
Ubipix (http://www.ubipix.com/) <http://www.ubipix.com/>

iGeotec Ltd.,
Block 8,
Blackrock Business Park,
Carysfort Avenue,
Blackrock,
Co. Dublin,
A94 W209,
Ireland.
Tel: +353 1 437 6921
Mob: +353 85 7217978
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20220613/327de05a/attachment-0001.htm>


More information about the MapServer-users mailing list