Make WordPress Core

Changeset 963


Ignore:
Timestamp:
03/08/2004 05:12:11 AM (20 years ago)
Author:
rboren
Message:

rewrite_rules() tweaks. Use rewrite_rules() in options-permalink.php.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/options-permalink.php

    r961 r963  
    101101if ('/' != substr($site_root, -1)) $site_root = $site_root . '/';
    102102
    103 $rewritecode = array(
    104     '%year%',
    105     '%monthnum%',
    106     '%day%',
    107     '%postname%',
    108     '%post_id%'
    109 );
    110 $rewritereplace = array(
    111     '([0-9]{4})?',
    112     '([0-9]{1,2})?',
    113     '([0-9]{1,2})?',
    114     '([0-9a-z-_]+)?',
    115     '([0-9]+)?'
    116 );
    117 $queryreplace = array (
    118     'year=',
    119     'monthnum=',
    120     'day=',
    121     'name=',
    122     'p='
    123 );
    124 
    125 
    126 
    127 $match = str_replace('/', '/?', $permalink_structure);
    128 $match = preg_replace('|/[?]|', '', $match, 1);
    129 
    130 $match = str_replace($rewritecode, $rewritereplace, $match);
    131 $match = preg_replace('|[?]|', '', $match, 1);
    132 
    133 $feedmatch = str_replace('?/?', '/', $match);
    134 $trackbackmatch = $feedmatch;
    135 
    136 preg_match_all('/%.+?%/', $permalink_structure, $tokens);
    137 
    138 $query = 'index.php?';
    139 $feedquery = 'wp-feed.php?';
    140 $trackbackquery = 'wp-trackback.php?';
    141 for ($i = 0; $i < count($tokens[0]); ++$i) {
    142     if (0 < $i) {
    143         $query .= '&';
    144         $feedquery .= '&';
    145         $trackbackquery .= '&';
    146     }
    147 
    148     $query_token = str_replace($rewritecode, $queryreplace, $tokens[0][$i]) . '$'. ($i + 1);
    149     $query .= $query_token;
    150     $feedquery .= $query_token;
    151     $trackbackquery .= $query_token;
    152 }
    153 ++$i;
    154 
    155 // Add post paged stuff
    156 $match .= '([0-9]+)?/?';
    157 $query .= "&page=$$i";
    158 
    159 // Add post feed stuff
    160 $feedregex = '(feed|rdf|rss|rss2|atom)/?';
    161 $feedmatch .= $feedregex;
    162 $feedquery .= "&feed=$$i";
    163 
    164 // Add post trackback stuff
    165 $trackbackregex = 'trackback/?';
    166 $trackbackmatch .= $trackbackregex;
    167 
    168 // Site feed
    169 $sitefeedmatch = 'feed/?([0-9a-z-_]+)?/?$';
    170 $sitefeedquery = $site_root . 'wp-feed.php?feed=$1';
    171 
    172 // Site comment feed
    173 $sitecommentfeedmatch = 'comments/feed/?([0-9a-z-_]+)?/?$';
    174 $sitecommentfeedquery = $site_root . 'wp-feed.php?feed=$1&withcomments=1';
    175 
    176 // Code for nice categories, currently not very flexible
    177 $front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
    178         $catmatch = $front . 'category/';
    179         $catmatch = preg_replace('|^/+|', '', $catmatch);
    180         $authormatch = $front . 'author/';
    181         $authormatch = preg_replace('|^/+|', '', $authormatch);
    182 
    183103?>
    184104<form action"">
    185105  <textarea rows="5" style="width: 100%;">RewriteEngine On
    186106RewriteBase <?php echo $site_root; ?>
    187 RewriteRule ^<?php echo $match; echo '$ ' . $site_root . $query ?> [QSA]
    188 RewriteRule ^<?php echo $feedmatch; echo '$ ' . $site_root . $feedquery ?> [QSA]
    189 RewriteRule ^<?php echo $trackbackmatch; echo '$ ' . $site_root . $trackbackquery ?> [QSA]
    190 RewriteRule ^<?php echo $catmatch; ?>(.*)/<?php echo $feedregex ?>$ <?php echo $site_root; ?>wp-feed.php?category_name=$1&feed=$2 [QSA]
    191 RewriteRule ^<?php echo $catmatch; ?>?(.*) <?php echo $site_root; ?>index.php?category_name=$1 [QSA]
    192 RewriteRule ^<?php echo $authormatch; ?>(.*)/<?php echo $feedregex ?>$ <?php echo $site_root; ?>wp-feed.php?author_name=$1&feed=$2 [QSA]
    193 RewriteRule ^<?php echo $authormatch; ?>?(.*) <?php echo $site_root; ?>index.php?author_name=$1 [QSA]
    194 RewriteRule ^<?php echo $sitefeedmatch; ?> <?php echo $sitefeedquery ?> [QSA]
    195 RewriteRule ^<?php echo $sitecommentfeedmatch; ?> <?php echo $sitecommentfeedquery ?> [QSA]</textarea>
    196     </form>
     107<?php
     108$rewrite = rewrite_rules();
     109foreach ($rewrite as $match => $query) {
     110    echo 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA]\n";
     111}
     112?></textarea>
     113</form>
    197114</div>
    198115<?php
  • trunk/wp-includes/functions.php

    r957 r963  
    14021402                            '([0-9]{1,2})?',
    14031403                            '([0-9]{1,2})?',
    1404                             '([0-9a-z-]+)?',
     1404                            '([0-9a-z_-]+)?',
    14051405                            '([0-9]+)?'
    14061406                            );
     
    14441444
    14451445    // Add post paged stuff
    1446     $match .= '([0-9]+)?/?';
     1446    $match .= '([0-9]+)?/?$';
    14471447    $query .= '&page=' . preg_index($i, $matches);
    14481448
    14491449    // Add post feed stuff
    1450     $feedregex = '(feed|rdf|rss|rss2|atom)/?';
     1450    $feedregex = '(feed|rdf|rss|rss2|atom)/?$';
    14511451    $feedmatch .= $feedregex;
    14521452    $feedquery .= '&feed=' . preg_index($i, $matches);
    14531453
    14541454    // Add post trackback stuff
    1455     $trackbackregex = 'trackback/?';
     1455    $trackbackregex = 'trackback/?$';
    14561456    $trackbackmatch .= $trackbackregex;
    14571457
    14581458    // Site feed
    1459     $sitefeedmatch = 'feed/?([0-9a-z-]+)?/?$';
     1459    $sitefeedmatch = 'feed/?([0-9a-z_-]+)?/?$';
    14601460    $sitefeedquery = $site_root . 'wp-feed.php?feed=' . preg_index(1, $matches);
    14611461
    14621462    // Site comment feed
    1463     $sitecommentfeedmatch = 'comments/feed/?([0-9a-z-]+)?/?$';
     1463    $sitecommentfeedmatch = 'comments/feed/?([0-9a-z_-]+)?/?$';
    14641464    $sitecommentfeedquery = $site_root . 'wp-feed.php?feed=' . preg_index(1, $matches) . '&withcomments=1';
    14651465
     
    14911491                     $match => $query,
    14921492                     $feedmatch => $feedquery,
    1493                      $trackbackmatch => $tracbackquery,
     1493                     $trackbackmatch => $trackbackquery,
    14941494                     $sitefeedmatch => $sitefeedquery,
    14951495                     $sitecommentfeedmatch => $sitecommentfeedquery
Note: See TracChangeset for help on using the changeset viewer.