【问题标题】:htaccess redirect specific url to another domainhtaccess 将特定的 url 重定向到另一个域
【发布时间】: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


    【解决方案1】:

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

    类似的东西;

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

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

    【讨论】:

    • 我不允许更改 w 参数。如何在 htaccess 正则表达式中将?w= 设为字符串
    猜你喜欢
    • 2015-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 2020-05-04
    相关资源
    最近更新 更多