简体   繁体   English

重写 Apache Query_String

[英]Rewrite Apache Query_String

I have a query string URL: http://localhost/cgi-bin/qgis_mapserv.fcgi?map=/home/qgis/project/map.qgs.我有一个查询字符串 URL: http://localhost/cgi-bin/qgis_mapserv.fcgi?map=/home/qgis/project/map.qgs。 I want to hind the map.qgs path in the variable MAP.我想在变量 MAP 中隐藏 map.qgs 路径。 Besides the map variable, there are some variables (version, request, service, etc).除了 map 变量外,还有一些变量(版本、请求、服务等)。 Here is what I need:这是我需要的:

RewriteRule: Pattern: ^cgi-bin/qgis_mapserv.fcgi?map=map.qgs&(. )$ Substitution: ^cgi-bin/qgis_mapserv.fcgi?map=/home/qgis/project/map.qgs&(. )$重写规则:模式:^cgi-bin/qgis_mapserv.fcgi?map=map.qgs&(. )$ 替换:^cgi-bin/qgis_mapserv.fcgi?map=/home/qgis/project/map.qgs&(. )$

Find bellow my unsuccessful attempt:在下面找到我不成功的尝试:

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/cgi-bin/qgis_mapserv.fcgi$
RewriteCond %{QUERY_STRING} ^map=([A-Za-z0-9.-_]+)$
RewriteRule ^cgi-bin/qgis_mapserv.fcgi?(.*)$ cgi-bin/qgis_mapserv.fcgi?$1

Note: The map variable can show up in the pattern uRL anywhere among the other variables.注意:map 变量可以出现在模式 uRL 中的其他变量中的任何位置。

I wonder what I am missing on the code above我想知道我在上面的代码中缺少什么

You are almost there.你快到了。 The reason why your rule isn't working is because you can't test queryString in pattern of a RewriteRule.您的规则不起作用的原因是您无法以 RewriteRule 的模式测试 queryString。

You need to change your rule's pattern to您需要将规则的模式更改为

  RewriteRule ^cgi-bin/qgis_mapserv.fcgi$

With this change your htaccess rules will look like:通过此更改,您的 htaccess 规则将如下所示:

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/cgi-bin/qgis_mapserv.fcgi$
RewriteCond %{QUERY_STRING} ^map=([A-Za-z0-9./-_]+)/map.qgs$
RewriteRule ^/?cgi-bin/qgis_mapserv.fcgi$ /cgi-bin/qgis_mapserv.fcgi?%1 [R,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM