[wp-hackers] WP_Rewrite without query var

SCOTT TAYLOR scott.c.taylor at mac.com
Sat Aug 25 21:10:45 UTC 2012


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


More information about the wp-hackers mailing list