Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 百分比符号(%或%25)在路径中不起作用_Php_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Php 百分比符号(%或%25)在路径中不起作用

Php 百分比符号(%或%25)在路径中不起作用,php,.htaccess,mod-rewrite,url-rewriting,Php,.htaccess,Mod Rewrite,Url Rewriting,我正在尝试从以下位置重定向用户: http://example.com/search?poster=ABC123 到http://example.com/name/ABC123 在$_GET['poster']变量中,我还允许用户输入通配符搜索%。这就是问题所在。当用户输入%converts作为路径中的第一个字母时,会出现如下错误: Forbidden You don't have permission to access /name/%25test on this server. Addit

我正在尝试从以下位置重定向用户:

http://example.com/search?poster=ABC123 到http://example.com/name/ABC123

在$_GET['poster']变量中,我还允许用户输入通配符搜索%。这就是问题所在。当用户输入%converts作为路径中的第一个字母时,会出现如下错误:

Forbidden
You don't have permission to access /name/%25test on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
但是,在字符串中的任何其他位置使用通配符都可以

这是我的.htaccess文件

Options -MultiViews
RewriteEngine On
Options -Indexes

RewriteBase /search
RewriteCond %{REQUEST_FILENAME}  !-d
RewriteCond %{REQUEST_FILENAME}  !-f
RewriteCond %{REQUEST_FILENAME}  !-l
RewriteRule ^name/(.+)$ /?poster=$1 [QSA,L]
RewriteRule ^content/(.+)$ /?content=$1 [QSA,L]
RewriteRule ^title/(.+)$ /?title=$1 [QSA,L]
我的真实网站示例:

http://archive.rookstat.net/name/%25he <--- Error
http://archive.rookstat.net/name/he%25 <--- Works
http://archive.rookstat.net/name/hello <--- Works
似乎它认为这是一个文件路径,而不是一个url…

请尝试使用B标志重新编码反向引用


文档中的示例与您的用例完全匹配,我无法更好地解释它。

百分比%符号是为url编码字符保留的。我建议对输入的搜索词进行base64编码,然后在搜索函数中进行解码

$query = base64_encode($wildcard_query);

$search_term = base64_decode($_GET['poster']);

我试过了,但还是不行。我尝试了[B]和其他方法。如果您使用的是mySQL查询,请注意不要将用户定义的查询直接输入到数据库中,因为您可能会受到SQL注入攻击。请参阅:[link]是的,我正在使用pdo和准备好的语句来获取数据
$query = base64_encode($wildcard_query);

$search_term = base64_decode($_GET['poster']);