Php 将查询字符串重定向到另一个url
我想重定向包含查询字符串的URL 范例- domain/user.php?username=tom&age=25&location=japan 我想将它重定向到另一个url domain2/profile.php?u=tom&age=25&location=japan&page=current 试过了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
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]