我想将带有参数的特定 URL 重定向到另一个域
http://domain.tld/buy/?w=X1234到http://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和伙计们!我从这里开始理解正则表达式^_^