简体   繁体   English

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

[英]Redirect query strings to another url

I want to redirect my urls that have query strings 我想重定向具有查询字符串的网址

example - 例子-

domain/user.php?username=tom&age=25&location=japan 域/ user.php的?用户名=汤姆和年龄= 25&位置=日本

I want to redirect it to a an another url 我想将其重定向到另一个网址

domain2/profile.php?u=tom&age=25&location=japan&page=current DOMAIN2 / profile.php?U =汤姆和年龄= 25&位置=日本&页=电流

Tried it 试过了

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

is not working 不管用

How can I do it? 我该怎么做?

You will need to use %{QUERY_STRING} server variable to match against the query string 您将需要使用%{QUERY_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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM