Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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/9/solr/3.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 将查询字符串重定向到另一个url_Php_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Php 将查询字符串重定向到另一个url

Php 将查询字符串重定向到另一个url,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我想重定向包含查询字符串的URL 范例- domain/user.php?username=tom&age=25&location=japan 我想将它重定向到另一个url domain2/profile.php?u=tom&age=25&location=japan&page=current 试过了 RewriteRule user.php http://domain2.com/profile.php?u=tom&age=25&location=japan&page=c

我想重定向包含查询字符串的URL

范例-

domain/user.php?username=tom&age=25&location=japan

我想将它重定向到另一个url

domain2/profile.php?u=tom&age=25&location=japan&page=current

试过了

RewriteRule user.php http://domain2.com/profile.php?u=tom&age=25&location=japan&page=current [R=301]
它不起作用了


我怎么做

您需要使用%{QUERY\u STRING}服务器变量来匹配查询字符串

RewriteEngine On
RewriteCond %{QUERY_STRING} ^username=([^&]+)&age=([^&]+)&location=([^&]+) [NC] 
RewriteRule ^user\.php$ http://domain2.com/profile.php?u=%1&age=%2&location=%3&page=current [NE,NC,R,L]