php - 如何通过 htaccess 在 url 中允许 1-9 a-z A-Z - _ %?

标签 php regex .htaccess

我想在 url (1-9, a-z, A-z, -, _, %) 中允许

我在 htaccess 中有以下代码

RewriteRule ^shop/search/([a-zA-Z0-9_-]+)/?$  shop.php?search=$1 [QSA,NC]

问题:在 url 中传递空格时 示例

domain.com/shop/search/my%20keyword

它不工作

基本上我想通过 htaccess 在 url 中允许 % 怎么做?

最佳答案

... it is matched against the (%-decoded) URL-path of the request ...

source , 强调我的。

mod_rewrite 永远不会看到 %,它将 %20 解码为一个空格。如果您想在 URL 中接受 %20,则向字符类添加空格。

关于php - 如何通过 htaccess 在 url 中允许 1-9 a-z A-Z - _ %?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38966322/

相关文章:

php - 来自 JSON 的 mysql 中的 bind_param

php - 搜索不返回多个关键字的结果

php - 以特定字符串开头和结尾且中间没有(其他)字符串的正则表达式

python - 从具有特定模式的 txt 文件创建 Pandas DataFrame

.htaccess - 重写基本: from specific url to another specific url

.htaccess - 如何从 slim 框架 URL 中删除 index.php

apache - 我可以从 .htaccess 文件编写 HTML 响应吗

php - 来自数据库的漂亮网址

Python正则表达式剥离脚本标签

php - 在 PHP 中迭代复杂的关联数组