I'm trying to add some rewrite rules to a plugin that is supposed to redirect to different urls, basically rotates through urls I add in the admin.
Example: The plugin creates mydomain.com/recommends/walmart/ and when a visitor hits this url he gets redirected. The /recommends/ part does not exist as page or post on my wordpress install and is only supposed to make the urls look nice and the user can enter in the plugins settings page the name that should be used for this redirect directory...
Here is the code I am using:
// Add rewrite rule and flush on plugin activation
register_activation_hook( __FILE__, 'aff_redirs_activate' );
function aff_redirs_activate() {
aff_redirs_rewrite();
flush_rewrite_rules();
}
// Flush on plugin deactivation
register_deactivation_hook( __FILE__, 'aff_redirs_deactivate' );
function aff_redirs_deactivate() {
flush_rewrite_rules();
}
// Create new rewrite rule
add_action( 'init', 'aff_redirs_rewrite' );
function aff_redirs_rewrite() {
add_rewrite_rule( "{$aff_path}/([^/]+)/?$", "redirect.php?affredir=true&redirect=$matches[1]", "top" );
}
The weird thing is now, when I use index.php in my rewrite rule(s) it doesn't add it to the htaccess on my local install, when I use anything else it works without problems
add_rewrite_rule( "{$aff_path}/([^/]+)/?$", "index.php?affredir=true&redirect=$matches[1]", "top" );
Can anybody help me out here, I'm really going nuts over this "little" issue :) Thank you!