• I am adding a rewrite rule in the simplest way I know how, which is something like this:

    function my_flush_rewrite_rules(){
    
    	global $wp_rewrite;
    	$wp_rewrite->flush_rules();
    
    }
    
    function my_add_rewrite_rule($wp_rewrite){
    
    	$feed_rules = array(
    		'.*myRequestedSpecialThing$' => 'index.php?my_parameter=1'
    	);
    	$wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
    
    }
    
    function my_add_query_vars($query_vars){
    
    	$query_vars[] = 'my_parameter';
    	return $query_vars;
    
    }
    
    function my_template_redirect(){
    
    	global $wp_query;
    	if(array_key_exists('my_parameter', $wp_query->query_vars)){
    		do_my_special_stuff_here();
    		die;
    	}
    }
    
    add_action('init',						'my_flush_rewrite_rules');
    add_action('generate_rewrite_rules',	'my_add_rewrite_rule');
    add_filter('query_vars',				'my_add_query_vars');
    add_action('template_redirect', 		'my_template_redirect');

    but I am getting a redirect (301 Moved Permanently, which is basically just adding a trailing slash) that I do not want. Is this WordPress or something on my server?

    Also is there a better or simpler way to work with WordPress rewrites?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘trying to add rewrite rules, getting unexpected redirect.’ is closed to new replies.