Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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 如何使用RewriteRule进行不可见的搜索查询?_Php_Mysql_.htaccess_Mod Rewrite - Fatal编程技术网

Php 如何使用RewriteRule进行不可见的搜索查询?

Php 如何使用RewriteRule进行不可见的搜索查询?,php,mysql,.htaccess,mod-rewrite,Php,Mysql,.htaccess,Mod Rewrite,在此之前,我想说,我一直在研究,但我仍然没有找到解决这个问题的办法。 我想做一个无形的重定向。使用此URL进行搜索而不重定向到另一个页面,因为我应该检查MySQL数据库中的user@user\u name以检索其用户配置文件 PHP脚本搜索.PHP 后果 1. 与: 重写规则^@[_A-Za-z0-9]+/search/X.*$/profile/search/search.php?用户=$1&q=$2[L] 和 www.localhost.com/@user\u name/search/X55

在此之前,我想说,我一直在研究,但我仍然没有找到解决这个问题的办法。 我想做一个无形的重定向。使用此URL进行搜索而不重定向到另一个页面,因为我应该检查MySQL数据库中的user@user\u name以检索其用户配置文件

PHP脚本搜索.PHP 后果 1. 与: 重写规则^@[_A-Za-z0-9]+/search/X.*$/profile/search/search.php?用户=$1&q=$2[L] 和 www.localhost.com/@user\u name/search/X55 它回来了 用户:用户名 问题:55/

2. 与: 重写规则^@[\u A-Za-z0-9]+/search/?q=.*$/profile/search/search.php?user=$1&q=$2[L] 和 www.localhost.com/@user\u name/search/?q=string 它给出了一个服务器错误。 请帮忙,谢谢

必须使用标志传递查询字符串:

RewriteRule ^@([_A-Za-z0-9]+)/search/?$ /profile/search/search.php?user=$1 [QSA,L]
..search/?$上的问号将斜杠字符/作为可选字符:

localhost.com/@user_name/search/?q=string 
localhost.com/@user_name/search?q=string 
请记住,重写规则与查询字符串不匹配。它仅与请求URI匹配。您只需要在URL中添加QSA现有查询字符串Append标志。你的规则应该是:

RewriteRule ^@(\w+)/search/?$ /profile/search/search.php?user=$1 [L,QSA]

非常感谢,它工作得很好。我不知道QSA,再次非常感谢。
localhost.com/@user_name/search/?q=string 
localhost.com/@user_name/search?q=string 
RewriteRule ^@(\w+)/search/?$ /profile/search/search.php?user=$1 [L,QSA]