regex - Rewrite rule accepting #
问题描述
I have the current RewriteRule:
RewriteRule ^search/([0-9a-zA-Z-\s-:]+)(/?)$ search.php?search=$1 [NC,L,NE]
I'm wanting to have an url like this /search/#ff2266/, to accept hex (with the #) colors in the url and then have this value in the $_GET['search'] variable. But not only this, but I'm having problem with the #.
Is there any way i could do something like this: ([#0-9a-zA-Z-\s-:]+) ?
I've tried the rule:
RewriteRule ^search/(.*)(/?)$ search.php?search=$1 [NC,L,NE]
And then in the search.php the following code:
echo "var_dump($_GET): ";
var_dump($_GET);
and with the url /search/#f44336/ the result is:
var_dump(Array): array(0) { }
解决方案
请参阅,# 之后的 URI 部分称为“片段”,并且根据定义仅在客户端可用/处理(请参阅https://en.wikipedia.org/wiki/Fragment_identifier)。
在客户端,可以使用带有 window.location.hash 的 javaScript 来访问它。
如果您想在搜索文件中访问该数字,您可以将其传递到那里而不使用哈希字符并以这种方式使用它。
推荐阅读
- javascript - React/JS 中的搜索过滤器
- javascript - 如何按特定顺序排列过滤器 javascript/reactjs
- html - 默认输入类型时间“手动输入”
- apache-spark - PySpark:如何计算满足最后一个条件之间的天数(正面与负面)
- ionic-framework - Ionic CLI - 6 加载资源失败:服务器响应状态为 404(未找到)
- r - 如何使用 tidyverse 在 r 中的数据框中重新评估已更改的单元格值
- c - 在 GCC 3.2、4.4 和 5.4 的 C89 中启用 long long
- braintree-sandbox - 在 Braintree 中使用托管字段时获取信用卡品牌并显示错误消息
- jenkins - 排队整个 Jenkins 管道
- bash - 使用 bash 操作基因库文件