简体   繁体   English

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

[英]Redirect url to another url with query string

I want to redirect with .htaccess 我想用.htaccess重定向

http://www.site1.com/pages/?url=http://www.gooogle.com/xyz/jkjk.html http://www.site1.com/pages/?url=http://www.gooogle.com/xyz/jkjk.html

to

http://tracking.site2.com/s?key=123456789&url=http://www.gooogle.com/xyz/jkjk.html http://tracking.site2.com/s?key=123456789&url=http://www.gooogle.com/xyz/jkjk.html

RewriteEngine On
RewriteCond   %{REQUEST_URI}    ^/pages/?$
RewriteCond   %{QUERY_STRING}   ^url=(.+)$
RewriteRule   ^(.*)$ http://tracking.site2.com/s?key=123456789&url=$1  [R=301,L]

Tried this.. failed. 尝试这个..失败。 Please help me with this 请在这件事上给予我帮助

You can use this rule in root .htaccess of server1: 您可以在server1的根.htaccess中使用此规则:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^url=([^&]+) [NC]
RewriteRule ^pages/(.*)$ http://tracking.site2.com/s?key=123456789&url=%1 [QSA,NC,NE,R=301,L]

Fro back referencing captured group from RewriteCond we need to use %1 , %2 etc instead of $1 , $2 . RewriteCond来回引用捕获的组,我们需要使用%1%2等而不是$1$2

如果要查询字符串,请像下面这样添加QSA(查询字符串追加)的附加标志:[R = 301,QSA,L]

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

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