I have an ad rotate plugin installed to display a few ads on my site but the plugin is coded so that it uses the full directory in the ad count link. I would like to know if there's something easy to put in my htacces to cloak the link. So for example:

http://mysite.com/wp-content/plugins/ad-rotating-plugin/rotate.php?trackerid=1

needs to look like:

http://mysite.com/rotate.php?trackerid=1 (actually any variation of this is fine, I just don't want that full wp-content/plugins/ directory shown in the link).

I've tried a few plugins but not getting the desired results. To recap, I want the link to SHOW as the bottom link, but when clicked, be taken to the top link, and I need that trackerid=# to stay the generated id, so I only want to cloak part of the link. Is there something I can put in my htaccess to do this?

Thanks!

link|improve this question

feedback

1 Answer

up vote 2 down vote accepted

What you need to do is set up a custom rewrite. This can change something like http://site.com/rotate/1 to http://site.com/wp-content/plugins/ad-rotating-plugin/rotate.php?trackerid=1

Here is some untested code that might help:

<?php
/*
Plugin Name: Your Plugin
Plugin URI: 
Description: 
Version: 0.1
Author: 
Author URI: 
*/

// Add rewrite rule and flush on plugin activation
register_activation_hook( __FILE__, 'ad_rotate_activate' );
function ad_rotate_activate() {
    ad_rotate_rewrite();
    flush_rewrite_rules();
}

// Flush on plugin deactivation
register_deactivation_hook( __FILE__, 'ad_rotate_deactivate' );
function ad_rotate_deactivate() {
    flush_rewrite_rules();
}

// Create new rewrite rule
add_action( 'init', 'ad_rotate_rewrite' );
function ad_rotate_rewrite() {
    add_rewrite_rule( 'rotate/([^/]+)','/wp-content/plugins/ad-rotating-plugin/rotate.php?trackerid=$matches[1]','top' );
}
link|improve this answer
I tried adding this to my functions.php file and it didn't seem to do anything. Do I need to flush my permalinks? Or does this need to be its own plugin file? – RodeoRamsey Feb 8 '11 at 20:25
The code I wrote above was written as a plug-in ... not drop-in code for a functions.php file ... since you are working with a plug-in to begin with, I was making the assumption that you wanted to include the rewrite code in the plug-in. But you need to at least do the add_rewrite_rule() call and then flush your rewrite rules. – EAMann Feb 8 '11 at 20:43
@EAMann: Does this add the rule to the rewrite_rules item in wp_options? I looked at the code in wp-includes/rewrite.php and I'll be damned if I could say definitively one way or the other. If it does get saved, what prevents the rule from getting saved a whole lot of times? Enquiring minds want to know! – Peter Rowell Feb 8 '11 at 22:23
@Peter add_rewrite_rule() adds the rule to an array that's indexed based on the regular expression defined above (rotate/([^/]+)). So it can't be added multiple times. Take a look at the add_rule() method of the WP_Rewrite class (/wp-includes/rewrite.php around line 1797). – EAMann Feb 8 '11 at 22:32
@EAMann, thanks for the clarification. So would this work as a separate plugin, or should I put this directly in the plugin files being used? I tried adding it as a plugin on its own and didn't get any changes to the original links. I'm primarily a front-end designer so this stuff is a little foreign to me. Thanks! :) – RodeoRamsey Feb 8 '11 at 22:35
show 6 more comments
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.