Report this

What is the reason for this report?

Apache .htaccess RewriteRule QGIS-Server

Posted on April 7, 2021

According to URL [1], I would like to hind the file path value in the map variable using apache .htaccess RewriteRule. Based on discussions [2] and [3], I want to keep the same URL as in [1], but hind the file path as in [4]. My first attempt is:

RewriteEngine On RewriteRule ^cgi-bin/qgis_mapserv.fcgi?map=([A-Za-z0-9]+)$ cgi-bin/qgis_mapserv.fcgi?map=/home/qgis/project/$1 [NC, QSA]

[1] http://localhost/cgi-bin/qgis_mapserv.fcgi?MAP=/home/qgis/project/qgisdatapostgis.qgs

[2] link [3] link

[4] http://localhost/cgi-bin/qgis_mapserv.fcgi?MAP=qgisdatapostgis.qgs



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

If I understand correctly want to rewrite the URL to hide the file path in the map parameter, is that right?

You can update your RewriteRule to achieve this.

The RewriteRule can be added to your .htaccess file and it would look like this:

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^MAP=([A-Za-z0-9]+)\.qgs$
RewriteRule ^cgi-bin/qgis_mapserv\.fcgi$ /cgi-bin/qgis_mapserv.fcgi?MAP=/home/qgis/project/%1.qgs [L]

These rules will rewrite the URL http://localhost/cgi-bin/qgis_mapserv.fcgi?MAP=qgisdatapostgis.qgs to http://localhost/cgi-bin/qgis_mapserv.fcgi?MAP=/home/qgis/project/qgisdatapostgis.qgs internally while keeping the original URL in the browser.

Now, when you access http://localhost/cgi-bin/qgis_mapserv.fcgi?MAP=qgisdatapostgis.qgs, Apache should rewrite the URL internally to include the full file path while keeping the short URL visible in the browser

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.