【问题标题】:Wordpress. How can i rewrite one url with params to another pretty url?WordPress。如何将一个带有参数的 url 重写为另一个漂亮的 url?
【发布时间】:2020-11-09 15:18:32
【问题描述】:

我想重写网址

https://example.com/arenda-avtomobilej-2/?min_price=300&max_price=1200&limo-vip=on&wwf=on

https://example.com/arenda-avtomobilej-2/somepage/

并将所有获取参数保存到查询变量。

有人可以帮忙吗?

【问题讨论】:

    标签: wordpress url-rewriting


    【解决方案1】:

    add_rewrite_rule() [see]

    添加将 URL 结构转换为一组查询变量的重写规则。

    add_action('init',  function() {
        add_rewrite_rule( 'min_price/([0-9]+)[/]?$', 'index.php?min_price=$matches[1]', 'top' );
    } );
    
    // https://example.com/arenda-avtomobilej-2/min_price/800
    

    [See also]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-15
      • 1970-01-01
      • 2020-07-12
      • 2013-08-09
      • 2017-04-16
      • 1970-01-01
      • 1970-01-01
      • 2016-02-17
      相关资源
      最近更新 更多