简体   繁体   English

Apache mod_rewrite删除空查询字符串参数?

[英]Apache mod_rewrite remove empty query string parameters?

Is it possible to remove empty query string parameters from a URL with Apache's mod_rewrite? 是否可以使用Apache的mod_rewrite从URL中删除空查询字符串参数?

A simple PHP script has an HTML form which submits to itself via GET. 一个简单的PHP脚本具有HTML表单,该表单通过GET提交给自己。 The HTML form has many input fields and when submitting via GET the resulting URL can end up being incredibly long, for example... HTML表单具有许多输入字段,当通过GET提交时,结果URL可能会变得非常长,例如...
http://www.domain.org/script.php?var1=&var2=&var3=foo&var4= ... &var18=bar

This PHP script only processes query string paramters whose length is > 0. Empty query string params are ignored. 此PHP脚本仅处理长度大于0的查询字符串参数。空的查询字符串参数将被忽略。

Is anyone aware of a method that can clear the empty variables within the query string so the URL would become? 有谁知道一种方法可以清除查询字符串中的空变量,从而使URL变为?
http://www.domain.org/script.php?var3=foo&var18=bar

I realise I could do this within my PHP script by processing the GET array and building a new query string based on the GET array elements with values then do an HTTP header redirect. 我意识到我可以在PHP脚本中通过处理GET数组并基于具有值的GET数组元素构建新的查询字符串,然后执行HTTP标头重定向来做到这一点。 But that sounds pretty rubbish. 但这听起来很垃圾。

Is there was a better way of removing empty query string parameters from a URL? 有没有一种更好的方法可以从URL中删除空查询字符串参数?

It is possible but very ill-advised . 可能但很不明智 Empty (null) is perfectly legal value for any variable, how will you let the processor know that you want to set some of the variables to empty/null? 空(空)是任何变量的完全合法值 ,您如何让处理器知道您要将某些变量设置为空/空?

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

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