【发布时间】:2013-05-19 00:43:54
【问题描述】:
我想将带有参数的特定 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=
谢谢
更新:在阅读How to REGEX and .htaccess rewrite url后,我使用查询字符串解决了这个问题
RewriteCond %{QUERY_STRING} ^w=([a-zA-Z0-9]+)$
RewriteRule ^/*buy/$ http://anotherdomain.tld/product.php?id=%1 [NC,L,R=301]
感谢 stackoverflow 和各位!我从这里开始理解正则表达式^_^
【问题讨论】:
标签: .htaccess mod-rewrite