[wp-hackers] Rebuild all rewrite rules

Ankur Oberoi aoberoi at gmail.com
Wed Aug 17 06:02:32 UTC 2011


After a little more experimentation I think I got just what I am looking
for. Here's my code:

function tokblog_add_rewrite_rules( $wp_rewrite )
{
  // tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$
  $new_rules = array( 'developer/?$' => 'index.php?tag=developer' ,
                      'developer/(feed|rdf|rss|rss2|atom)/?$' =>
'index.php?tag=developer&feed='.$wp_rewrite->preg_index(1) ,
                      'developer/feed/(feed|rdf|rss|rss2|atom)/?$' =>
'index.php?tag=developer&feed='.$wp_rewrite->preg_index(1) );

  //​ Add the new rewrite rules into the top of the global rules array
  $wp_rewrite->rules = array_merge($new_rules, $wp_rewrite->rules);

  _log($wp_rewrite->rules);
}

add_action('generate_rewrite_rules', 'tokblog_add_rewrite_rules');

Thanks again for your help guys

On Tue, Aug 16, 2011 at 10:43 PM, Ankur Oberoi <aoberoi at gmail.com> wrote:

> Mike's solution seems to work, but I'm going to up the ante on the
> challenge some more. I also want the feeds for the developer tag to be
> available at /developer/feed (and all the derivative formats normally as
> well). Can I just add more rules? You can already tell I'm pretty bad with
> regex.
>
>
> On Tue, Aug 16, 2011 at 9:15 PM, Braydon <ronin at braydon.com> wrote:
>
>> What about using .htaccess rewrite rules?
>>
>> RewriteRule ^/etcetera/?$ /index.php?cat=1 [L,R=301]
>>
>> RewriteRule ^/etcetera/?$ /category/etc/ [L,R=301]
>>
>> Was trying to find a way for the URL to stay the same, but it's being
>> modified by PHP, so it's a lost cause....
>>
>>
>> On 08/16/2011 07:23 PM, Ankur Oberoi wrote:
>>
>>> oh wow, ur the man, otto!
>>>
>>> any idea what i can do about the rewrite rule i'm trying to make?
>>>
>>> I can see the rule getting added to the top of the array, but when i try
>>> to
>>> navigate to myblog.com/developer it pulls up a post that happens to
>>> start
>>> with developer as the first part of the pretty permanlink. in this case i
>>> have my permalink structure set to "/%postname%". Yes, yes, poor
>>> performance, I;m not happy with it either, but its part of the
>>> requirements.
>>>
>>> On Tue, Aug 16, 2011 at 7:06 PM, Otto<otto at ottodestruct.com>  wrote:
>>>
>>>  On Tue, Aug 16, 2011 at 9:02 PM, Ankur Oberoi<aoberoi at gmail.com>
>>>>  wrote:
>>>>
>>>>> been there done that, theres still a bunch of rules that exist for
>>>>> pages
>>>>>
>>>> i
>>>>
>>>>> deleted a while ago. any idea why that would happen?
>>>>>
>>>> Are they really deleted, or in the trash?
>>>>
>>>> -Otto
>>>> ______________________________**_________________
>>>> wp-hackers mailing list
>>>> wp-hackers at lists.automattic.**com <wp-hackers at lists.automattic.com>
>>>> http://lists.automattic.com/**mailman/listinfo/wp-hackers<http://lists.automattic.com/mailman/listinfo/wp-hackers>
>>>>
>>>>  ______________________________**_________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.**com <wp-hackers at lists.automattic.com>
>>> http://lists.automattic.com/**mailman/listinfo/wp-hackers<http://lists.automattic.com/mailman/listinfo/wp-hackers>
>>>
>>> !DSPAM:**4e4b261e324141804284693!
>>>
>>>
>> ______________________________**_________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.**com <wp-hackers at lists.automattic.com>
>> http://lists.automattic.com/**mailman/listinfo/wp-hackers<http://lists.automattic.com/mailman/listinfo/wp-hackers>
>>
>
>


More information about the wp-hackers mailing list