[wp-hackers] WP_Rewrite without query var

Chris McCoy chris at lod.com
Sun Aug 26 06:55:01 UTC 2012


Ya I switched to flush on register_activation_hook.

Which action would be the best to add the add_rewrite_rule to? Is init ok
for that?

-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com
[mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Kurt Payne
Sent: Saturday, August 25, 2012 11:36 PM
To: wp-hackers at lists.automattic.com
Subject: Re: [wp-hackers] WP_Rewrite without query var

Flushing the rewrite rules on init is not recommended.  This recreates the
.htaccess / web.config file on every page load (admin, ajax, and front end).

Try using an option or activation hook to only flush the rewrite rules when
you actually need to.


On Sat, Aug 25, 2012 at 2:15 PM, Chris McCoy <chris at lod.com> wrote:

> Ya I orig did that, but I wanted a more automated way of doing it 
> without the user adding it to .htaccess
>
> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com
> [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of SCOTT 
> TAYLOR
> Sent: Saturday, August 25, 2012 5:11 PM
> To: wp-hackers at lists.automattic.com
> Cc: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] WP_Rewrite without query var
>
> Use an Apache RewriteRule in .htaccess instead
>
> Sent from my iPhone
>
> On Aug 25, 2012, at 5:08 PM, Chris McCoy <chris at lod.com> wrote:
>
> > Im trying to rewrite a long file url to a shorter one.
> >
> > Basically I have zips in a plugin folder I want to rewrite to 
> > /downloads/filename.zip instead of 
> > /wp-content/plugins/plugin-name/zips/filename.zip
> >
> > Cant figure what im doing wrong.
> >
> > Here is what I have
> >
> > define('ZT_URL', plugins_url('zips/' , __FILE__));
> >
> > add_action('generate_rewrite_rules', 'cmm_add_rewrite_rules');
> >
> > function cmm_add_rewrite_rules( $wp_rewrite ) {
> >        $new_rules = array(
> >                "^downloads/(.+)\.zip$" => ZT_URL .
> > $wp_rewrite->preg_index(1)
> >        );
> >        $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; }
> >
> > add_action('init','cmm_flush_rules');
> >
> > function cmm_flush_rules(){
> >        global $wp_rewrite;
> >        $wp_rewrite->flush_rules();
> > }
> >
> > Any input is greatful.
> >
> >
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list