【问题标题】:Breaking of query-string and retrieving value查询字符串的中断和检索值
【发布时间】:2015-11-30 14:08:21
【问题描述】:

我在我的 httpd-apache 2.2 文件中使用了与以下类似的代码

<Location /local/*/*/*>
setHandler dispatcher-handler
RewriteEngine On
RewriteCond %{REQUEST_URI} ^.*.*.* [NC]
RewriteRule ^/?(.*)/(.*)/(.*)$ www.dns.com/product.html?state=$1&city=$2&product=$3 [R]
</Location>

当我在浏览器中给出 URL-www.dns.com/local/1/2/3 在日志中,查询中断如下:

state=opt/apache/httpserver/htdocs/local/1&city=2&product=3

我如何编码 httpd 文件,以便 state 必须只采用 1 而不是采用完整的“文档根”路径和“本地”?

理想情况下我想要state=1city=2product=3 我怎样才能实现这个功能?

【问题讨论】:

  • RewriteRule 仅匹配请求的 URI 的路径部分。如果要检查查询字符串的内容,则需要使用RewriteCond(有关详细信息,请参阅文档。)

标签: apache query-string httpd.conf


【解决方案1】:

问题是您的目标以“www.dns.com”开头,它缺少作为标准编译 URL 的协议部分“http://”。您可以通过将其更改为来轻松解决此问题

RewriteRule ^/?(.*)/(.*)/(.*)$ http://www.dns.com/product.html?state=$1&city=$2&product=$3 [R]

或使用当前主机的相对路径,如下所示:

RewriteRule ^/?(.*)/(.*)/(.*)$ /product.html?state=$1&city=$2&product=$3 [R]

【讨论】:

  • 我尝试使用 RewriteRule ^/?(.*)/(.*)/(.*)$ dns.com/product.html?state=$1&city=$2&product=$3 [R] 仍然遇到同样的问题...... ..如果我给 www.dns.com/local/1/2/3 ......state=opt/apache/httpserver/htdocs/local/1&city=2&product=3........我想摆脱“opt/apache/httpserver/htdocs/local”
  • 我尝试使用 RewriteRule ^/?(.*)/(.*)/(.*)$ dns.com/product.html?state=$1&city=$2&product=$3 [R] 仍然遇到同样的问题...... ..如果我给 www.dns.com/local/1/2/3 ......state=opt/apache/httpserver/htdocs/local/1&city=2&product=3........我想摆脱“opt/apache/httpserver/htdocs/local”
  • 再次阅读我的答案。
  • 我按照你提到的方式给出规则。它没有在我的评论中显示“http://”。我给了 DNS 和 'http://' -----------你提到的第二个解决方案也是如此。--- ------ state=opt/apache/httpserver/htdocs/publish-9001/local/1&city=2&product=3
  • 嗯,好的。那不好意思了。您确定您删除了之前的规则吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-11
  • 1970-01-01
相关资源
最近更新 更多