【问题标题】:redirection 301 with htaccess with variables in url使用 htaccess 重定向 301,并在 url 中使用变量
【发布时间】:2016-07-06 15:48:46
【问题描述】:

我在论坛上搜索过答案,但对我没有用。

我已经使用 Wordpress 重建了一个网站,并希望保留旧网址。

旧网址: /bingo/play-bingo-40/review?reviews_id=16

我们的网址: https://website.com/product/the-new-url-of-play-bingo-40/

我试过这个:

RewriteCond %{QUERY_STRING} ^reviews_id=([^&]+) [NC]
RewriteRule ^bingo/play-bingo-40/review https://website.com/product/the-new-url-of-play-bingo-40/? [R=301]

有人吗?

【问题讨论】:

标签: wordpress .htaccess mod-rewrite url-redirection


【解决方案1】:

您不使用查询字符串中的任何内容,因此您无需使用RewriteCond 进行捕获。您似乎使用了请求 URL 的一部分,因此您必须捕获这个

RewriteRule ^bingo/(.+?)/review https://example.com/product/the-new-url-of-$1/? [R,L]

要了解更多关于 mod_rewrite 的一般信息和正则表达式,请参阅http://httpd.apache.org/docs/current/rewrite/intro.html。正则表达式的另一个很好的参考是http://www.regular-expressions.info/

【讨论】:

    猜你喜欢
    • 2019-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    • 2021-04-01
    • 2016-05-30
    • 2021-01-06
    • 2013-07-29
    相关资源
    最近更新 更多