如何减少重写规则的数量?

时间:2016-01-07 作者:Marc Dingena

我正在为我的WordPress站点构建一个强大的过滤系统,我真的希望能为生成的URL创建永久链接。但由于我提供了大量不同的过滤选项,重写所需的不同规则正在失控。我目前正在运行80条重写规则,不知道这是否会严重影响我的网站的性能(尽管我猜这个问题的真正答案是“视情况而定”)。

问题是,每次我添加一个新的过滤器选项时,除非我能在正则表达式中捕获它,否则它会使规则数量加倍。How can I simplify rewrite rules with these requirements?

分类法可以包含在任何组合和任何顺序中,但必须始终位于下面提到的任何其他URL段之前。也允许不包含任何此类分类的URL。分类法包括genre, artist 以及内置的tag. URL段看起来像/genre/neurofunk/tag/bassdrive-xposure-show/artist/ben-xo+dj-liquid/;/20120826/20140513/;meta_value通过使用/by/ URL段,后跟键。为了能够区分内置键和自定义键,使用带前缀的下划线:/by/comment_count/ vs。/by/_downloads/;/asc/ 当我想按这种方式排序时,作为URL段/page/ 段

My rewrite rules

function tjnz_rewrite( $wp_rewrite ) {
    $rules = array(
        // with daterange + 3 params + orderby meta
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/asc\\/page\\/([0-9])\\/?$\' => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&datelo=\' . $wp_rewrite->preg_index(7) . \'&datehi=\' . $wp_rewrite->preg_index(8) . \'&mixmeta=\' . $wp_rewrite->preg_index(9) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(10),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/asc\\/?$\'                => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&datelo=\' . $wp_rewrite->preg_index(7) . \'&datehi=\' . $wp_rewrite->preg_index(8) . \'&mixmeta=\' . $wp_rewrite->preg_index(9) . \'&order=asc\',
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/page\\/([0-9])\\/?$\'      => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&datelo=\' . $wp_rewrite->preg_index(7) . \'&datehi=\' . $wp_rewrite->preg_index(8) . \'&mixmeta=\' . $wp_rewrite->preg_index(9) . \'&paged=\' . $wp_rewrite->preg_index(10),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/?$\'                     => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&datelo=\' . $wp_rewrite->preg_index(7) . \'&datehi=\' . $wp_rewrite->preg_index(8) . \'&mixmeta=\' . $wp_rewrite->preg_index(9),
        // with daterange + 3 params + orderby native
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/asc\\/page\\/([0-9])\\/?$\'  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&datelo=\' . $wp_rewrite->preg_index(7) . \'&datehi=\' . $wp_rewrite->preg_index(8) . \'&orderby=\' . $wp_rewrite->preg_index(9) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(10),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/asc\\/?$\'                 => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&datelo=\' . $wp_rewrite->preg_index(7) . \'&datehi=\' . $wp_rewrite->preg_index(8) . \'&orderby=\' . $wp_rewrite->preg_index(9) . \'&order=asc\',
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/page\\/([0-9])\\/?$\'       => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&datelo=\' . $wp_rewrite->preg_index(7) . \'&datehi=\' . $wp_rewrite->preg_index(8) . \'&orderby=\' . $wp_rewrite->preg_index(9) . \'&paged=\' . $wp_rewrite->preg_index(10),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/?$\'                      => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&datelo=\' . $wp_rewrite->preg_index(7) . \'&datehi=\' . $wp_rewrite->preg_index(8) . \'&orderby=\' . $wp_rewrite->preg_index(9),
        // with daterange + 3 params w/o orderby
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/page\\/([0-9])\\/?$\'                  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&datelo=\' . $wp_rewrite->preg_index(7) . \'&datehi=\' . $wp_rewrite->preg_index(8) . \'&paged=\' . $wp_rewrite->preg_index(9),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/?$\'                                 => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&datelo=\' . $wp_rewrite->preg_index(7) . \'&datehi=\' . $wp_rewrite->preg_index(8),

        // no daterange + 3 params + orderby meta
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(_.+?)\\/asc\\/page\\/([0-9])\\/?$\' => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&mixmeta=\' . $wp_rewrite->preg_index(7) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(8),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(_.+?)\\/asc\\/?$\'                => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&mixmeta=\' . $wp_rewrite->preg_index(7) . \'&order=asc\',
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(_.+?)\\/page\\/([0-9])\\/?$\'      => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&mixmeta=\' . $wp_rewrite->preg_index(7) . \'&paged=\' . $wp_rewrite->preg_index(8),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(_.+?)\\/?$\'                     => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&mixmeta=\' . $wp_rewrite->preg_index(7),
        // no daterange + 3 params + orderby native
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(.+?)\\/asc\\/page\\/([0-9])\\/?$\'  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&orderby=\' . $wp_rewrite->preg_index(7) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(8),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(.+?)\\/asc\\/?$\'                 => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&orderby=\' . $wp_rewrite->preg_index(7) . \'&order=asc\',
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(.+?)\\/page\\/([0-9])\\/?$\'       => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&orderby=\' . $wp_rewrite->preg_index(7) . \'&paged=\' . $wp_rewrite->preg_index(8),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(.+?)\\/?$\'                      => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&orderby=\' . $wp_rewrite->preg_index(7),
        // no daterange + 3 params w/o orderby
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/page\\/([0-9])\\/?$\'                  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6) . \'&paged=\' . $wp_rewrite->preg_index(7),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/?$\'                                 => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&\' . $wp_rewrite->preg_index(5) . \'=\' . $wp_rewrite->preg_index(6),

        // with daterange + 2 params + orderby meta
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/asc\\/page\\/([0-9])\\/?$\' => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&datelo=\' . $wp_rewrite->preg_index(5) . \'&datehi=\' . $wp_rewrite->preg_index(6) . \'&mixmeta=\' . $wp_rewrite->preg_index(7) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(8),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/asc\\/?$\'                => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&datelo=\' . $wp_rewrite->preg_index(5) . \'&datehi=\' . $wp_rewrite->preg_index(6) . \'&mixmeta=\' . $wp_rewrite->preg_index(7) . \'&order=asc\',
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/page\\/([0-9])\\/?$\'      => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&datelo=\' . $wp_rewrite->preg_index(5) . \'&datehi=\' . $wp_rewrite->preg_index(6) . \'&mixmeta=\' . $wp_rewrite->preg_index(7) . \'&paged=\' . $wp_rewrite->preg_index(8),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/?$\'                     => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&datelo=\' . $wp_rewrite->preg_index(5) . \'&datehi=\' . $wp_rewrite->preg_index(6) . \'&mixmeta=\' . $wp_rewrite->preg_index(7),
        // with daterange + 2 params + orderby native
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/asc\\/page\\/([0-9])\\/?$\'  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&datelo=\' . $wp_rewrite->preg_index(5) . \'&datehi=\' . $wp_rewrite->preg_index(6) . \'&orderby=\' . $wp_rewrite->preg_index(7) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(8),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/asc\\/?$\'                 => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&datelo=\' . $wp_rewrite->preg_index(5) . \'&datehi=\' . $wp_rewrite->preg_index(6) . \'&orderby=\' . $wp_rewrite->preg_index(7) . \'&order=asc\',
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/page\\/([0-9])\\/?$\'       => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&datelo=\' . $wp_rewrite->preg_index(5) . \'&datehi=\' . $wp_rewrite->preg_index(6) . \'&orderby=\' . $wp_rewrite->preg_index(7) . \'&paged=\' . $wp_rewrite->preg_index(8),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/?$\'                      => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&datelo=\' . $wp_rewrite->preg_index(5) . \'&datehi=\' . $wp_rewrite->preg_index(6) . \'&orderby=\' . $wp_rewrite->preg_index(7),
        // with daterange + 2 params w/o orderby
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/page\\/([0-9])\\/?$\'                  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(5) . \'&datelo=\' . $wp_rewrite->preg_index(5) . \'&datehi=\' . $wp_rewrite->preg_index(6) . \'&paged=\' . $wp_rewrite->preg_index(7),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/?$\'                                 => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(5) . \'&datelo=\' . $wp_rewrite->preg_index(5) . \'&datehi=\' . $wp_rewrite->preg_index(6),

        // no daterange + 2 params + orderby meta
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(_.+?)\\/asc\\/page\\/([0-9])\\/?$\' => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&mixmeta=\' . $wp_rewrite->preg_index(5) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(6),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(_.+?)\\/asc\\/?$\'                => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&mixmeta=\' . $wp_rewrite->preg_index(5) . \'&order=asc\',
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(_.+?)\\/page\\/([0-9])\\/?$\'      => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&mixmeta=\' . $wp_rewrite->preg_index(5) . \'&paged=\' . $wp_rewrite->preg_index(6),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(_.+?)\\/?$\'                     => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&mixmeta=\' . $wp_rewrite->preg_index(5),
        // no daterange + 2 params + orderby native
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(.+?)\\/asc\\/page\\/([0-9])\\/?$\'  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&orderby=\' . $wp_rewrite->preg_index(5) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(6),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(.+?)\\/asc\\/?$\'                 => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&orderby=\' . $wp_rewrite->preg_index(5) . \'&order=asc\',
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(.+?)\\/page\\/([0-9])\\/?$\'       => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&orderby=\' . $wp_rewrite->preg_index(5) . \'&paged=\' . $wp_rewrite->preg_index(6),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/by\\/(.+?)\\/?$\'                      => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4) . \'&orderby=\' . $wp_rewrite->preg_index(5),
        // no daterange + 2 params w/o orderby
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/page\\/([0-9])\\/?$\'                  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(5) . \'&paged=\' . $wp_rewrite->preg_index(6),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/(genre|tag|artist)\\/(.+?)\\/?$\'                                 => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(5),

        // with daterange + 1 param + orderby meta
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/asc\\/page\\/([0-9])\\/?$\' => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&datelo=\' . $wp_rewrite->preg_index(3) . \'&datehi=\' . $wp_rewrite->preg_index(4) . \'&mixmeta=\' . $wp_rewrite->preg_index(5) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(6),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/asc\\/?$\'                => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&datelo=\' . $wp_rewrite->preg_index(3) . \'&datehi=\' . $wp_rewrite->preg_index(4) . \'&mixmeta=\' . $wp_rewrite->preg_index(5) . \'&order=asc\',
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/page\\/([0-9])\\/?$\'      => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&datelo=\' . $wp_rewrite->preg_index(3) . \'&datehi=\' . $wp_rewrite->preg_index(4) . \'&mixmeta=\' . $wp_rewrite->preg_index(5) . \'&paged=\' . $wp_rewrite->preg_index(6),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/?$\'                     => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&datelo=\' . $wp_rewrite->preg_index(3) . \'&datehi=\' . $wp_rewrite->preg_index(4) . \'&mixmeta=\' . $wp_rewrite->preg_index(5),
        // with daterange + 1 param + orderby native
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/asc\\/page\\/([0-9])\\/?$\'  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&datelo=\' . $wp_rewrite->preg_index(3) . \'&datehi=\' . $wp_rewrite->preg_index(4) . \'&orderby=\' . $wp_rewrite->preg_index(5) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(6),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/asc\\/?$\'                 => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&datelo=\' . $wp_rewrite->preg_index(3) . \'&datehi=\' . $wp_rewrite->preg_index(4) . \'&orderby=\' . $wp_rewrite->preg_index(5) . \'&order=asc\',
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/page\\/([0-9])\\/?$\'       => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&datelo=\' . $wp_rewrite->preg_index(3) . \'&datehi=\' . $wp_rewrite->preg_index(4) . \'&orderby=\' . $wp_rewrite->preg_index(5) . \'&paged=\' . $wp_rewrite->preg_index(6),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/?$\'                      => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&datelo=\' . $wp_rewrite->preg_index(3) . \'&datehi=\' . $wp_rewrite->preg_index(4) . \'&orderby=\' . $wp_rewrite->preg_index(5),
        // with daterange + 1 param w/o orderby
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/([0-9]{8})\\/([0-9]{8})\\/page\\/([0-9])\\/?$\'                  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&datelo=\' . $wp_rewrite->preg_index(3) . \'&datehi=\' . $wp_rewrite->preg_index(4) . \'&paged=\' . $wp_rewrite->preg_index(5),
        \'filter\\/(genre|tag|artist)\\/(.+)\\/([0-9]{8})\\/([0-9]{8})\\/?$\'                                  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&datelo=\' . $wp_rewrite->preg_index(3) . \'&datehi=\' . $wp_rewrite->preg_index(4),

        // no daterange + 1 param + orderby meta
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/by\\/(_.+?)\\/asc\\/page\\/([0-9])\\/?$\' => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&mixmeta=\' . $wp_rewrite->preg_index(3) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(4),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/by\\/(_.+?)\\/asc\\/?$\'                => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&mixmeta=\' . $wp_rewrite->preg_index(3) . \'&order=asc\',
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/by\\/(_.+?)\\/page\\/([0-9])\\/?$\'      => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&mixmeta=\' . $wp_rewrite->preg_index(3) . \'&paged=\' . $wp_rewrite->preg_index(4),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/by\\/(_.+?)\\/?$\'                     => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&mixmeta=\' . $wp_rewrite->preg_index(3),
        // no daterange + 1 param + orderby native
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/by\\/(.+?)\\/asc\\/page\\/([0-9])\\/?$\'  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&orderby=\' . $wp_rewrite->preg_index(3) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(4),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/by\\/(.+?)\\/asc\\/?$\'                 => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&orderby=\' . $wp_rewrite->preg_index(3) . \'&order=asc\',
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/by\\/(.+?)\\/page\\/([0-9])\\/?$\'       => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&orderby=\' . $wp_rewrite->preg_index(3) . \'&paged=\' . $wp_rewrite->preg_index(4),
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/by\\/(.+?)\\/?$\'                      => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&orderby=\' . $wp_rewrite->preg_index(3),
        // no daterange + 1 param w/o orderby
        \'filter\\/(genre|tag|artist)\\/(.+?)\\/page\\/([0-9])\\/?$\'                  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&paged=\' . $wp_rewrite->preg_index(3),
        \'filter\\/(genre|tag|artist)\\/(.+)\\/?$\'                                  => \'index.php?\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2),


        // with daterange + 0 params + orderby meta
        \'filter\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/asc\\/page\\/([0-9])\\/?$\' => \'index.php?datelo=\' . $wp_rewrite->preg_index(1) . \'&datehi=\' . $wp_rewrite->preg_index(2) . \'&mixmeta=\' . $wp_rewrite->preg_index(3) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(4),
        \'filter\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/asc\\/?$\'                => \'index.php?datelo=\' . $wp_rewrite->preg_index(1) . \'&datehi=\' . $wp_rewrite->preg_index(2) . \'&mixmeta=\' . $wp_rewrite->preg_index(3) . \'&order=asc\',
        \'filter\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+?)\\/page\\/([0-9])\\/?$\'      => \'index.php?datelo=\' . $wp_rewrite->preg_index(1) . \'&datehi=\' . $wp_rewrite->preg_index(2) . \'&mixmeta=\' . $wp_rewrite->preg_index(3) . \'&paged=\' . $wp_rewrite->preg_index(4),
        \'filter\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(_.+)\\/?$\'                      => \'index.php?datelo=\' . $wp_rewrite->preg_index(1) . \'&datehi=\' . $wp_rewrite->preg_index(2) . \'&mixmeta=\' . $wp_rewrite->preg_index(3),
        // with daterange + 0 params + orderby native
        \'filter\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/asc\\/page\\/([0-9])\\/?$\'  => \'index.php?datelo=\' . $wp_rewrite->preg_index(1) . \'&datehi=\' . $wp_rewrite->preg_index(2) . \'&orderby=\' . $wp_rewrite->preg_index(3) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(4),
        \'filter\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/asc\\/?$\'                 => \'index.php?datelo=\' . $wp_rewrite->preg_index(1) . \'&datehi=\' . $wp_rewrite->preg_index(2) . \'&orderby=\' . $wp_rewrite->preg_index(3) . \'&order=asc\',
        \'filter\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+?)\\/page\\/([0-9])\\/?$\'       => \'index.php?datelo=\' . $wp_rewrite->preg_index(1) . \'&datehi=\' . $wp_rewrite->preg_index(2) . \'&orderby=\' . $wp_rewrite->preg_index(3) . \'&paged=\' . $wp_rewrite->preg_index(4),
        \'filter\\/([0-9]{8})\\/([0-9]{8})\\/by\\/(.+)\\/?$\'                       => \'index.php?datelo=\' . $wp_rewrite->preg_index(1) . \'&datehi=\' . $wp_rewrite->preg_index(2) . \'&orderby=\' . $wp_rewrite->preg_index(3),
        // with daterange + 0 params w/o orderby
        \'filter\\/([0-9]{8})\\/([0-9]{8})\\/page\\/([0-9])\\/?$\'                  => \'index.php?datelo=\' . $wp_rewrite->preg_index(1) . \'&datehi=\' . $wp_rewrite->preg_index(2) . \'&paged=\' . $wp_rewrite->preg_index(3),
        \'filter\\/([0-9]{8})\\/([0-9]{8})\\/?$\'                                 => \'index.php\',

        // no daterange + 0 params + orderby meta
        \'filter\\/by\\/(_.+?)\\/asc\\/page\\/([0-9])\\/?$\' => \'index.php?mixmeta=\' . $wp_rewrite->preg_index(1) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(2),
        \'filter\\/by\\/(_.+?)\\/asc\\/?$\'                => \'index.php?mixmeta=\' . $wp_rewrite->preg_index(1) . \'&order=asc\',
        \'filter\\/by\\/(_.+?)\\/page\\/([0-9])\\/?$\'      => \'index.php?mixmeta=\' . $wp_rewrite->preg_index(1) . \'&paged=\' . $wp_rewrite->preg_index(2),
        \'filter\\/by\\/(_.+)\\/?$\'                      => \'index.php?mixmeta=\' . $wp_rewrite->preg_index(1),
        // no daterange + 0 params + orderby native
        \'filter\\/by\\/(.+?)\\/asc\\/page\\/([0-9])\\/?$\'  => \'index.php?orderby=\' . $wp_rewrite->preg_index(1) . \'&order=asc&paged=\' . $wp_rewrite->preg_index(2),
        \'filter\\/by\\/(.+?)\\/asc\\/?$\'                 => \'index.php?orderby=\' . $wp_rewrite->preg_index(1) . \'&order=asc\',
        \'filter\\/by\\/(.+?)\\/page\\/([0-9])\\/?$\'       => \'index.php?orderby=\' . $wp_rewrite->preg_index(1) . \'&paged=\' . $wp_rewrite->preg_index(2),
        \'filter\\/by\\/(.+)\\/?$\'                       => \'index.php?orderby=\' . $wp_rewrite->preg_index(1),
        // no daterange + 0 params w/o orderby
        \'filter\\/page\\/([0-9])\\/?$\'                  => \'index.php?paged=\' . $wp_rewrite->preg_index(1),
        \'filter\\/?$\'                                 => \'index.php\'
    );
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;
}

1 个回复
最合适的回答,由SO网友:TheDeadMedic 整理而成

我想说的是,这是一种微观优化,你的努力会更好地花在其他地方——额外的80条规则在WordPress的总运行时间中只需眨眼(它们只是一个foreach 循环使用preg_match).

您最好确保有效地设计任何自定义数据库表,查询高效,并尽可能利用缓存。

Update:in-depth look at WordPress\' cache system. 此系列打开caching at the page level 也值得一读。

相关推荐

regEx wp core file

我对WordPress处理创建页面锚定的方式有一个问题。页面定位按钮已在WordPress TinyMCE代码中定义。。并且可以使用Ultimate Tinymce 或者TinyMCE Advanced 插件。单击页面定位按钮时,将打开一个弹出窗口,要求定义定位的名称。如果输入所有字母(myAnchor), 一切正常。如果输入字母和数字,则以字母开头(myAnchor123), 它按预期工作。但当输入以数字开头的锚时(123myAnchor)... 引发错误。这是WordPress文件中的代码wp-inc