1

我想将带有参数的特定 URL 重定向到另一个域

http://domain.tld/buy/?w=X1234http://anotherdomain.tld/product.php?id=X1234

这是我的 htaccess

RewriteCond %{REQUEST_URI} !^/*buy/(.*)$ [NC]
RewriteRule ^/*buy/?w=([a-zA-Z0-9]+)$ http://anotherdomain.tld/product.php?id=$1 [NC,L,R=301]

但不工作。也许问题是参数 ?w=

谢谢

更新:在阅读如何 REGEX 和 .htaccess 重写 url之后,我通过使用查询字符串解决了这个问题

RewriteCond %{QUERY_STRING} ^w=([a-zA-Z0-9]+)$
RewriteRule ^/*buy/$ http://anotherdomain.tld/product.php?id=%1 [NC,L,R=301]

谢谢stackoverflow和伙计们!我从这里开始理解正则表达式^_^

4

1 回答 1

0

没错,你的参数不会被拾取,但它们可以被传递。

就像是;

RewriteRule ^buy/([a-zA-Z0-9]+)$ http://anotherdomain.tld/product.php?id=$1 [NC,L,R=301]

您的原始网址在哪里;/买/X1234

于 2013-05-19T00:53:44.113 回答