I was working with rewriting a custom rule for my wordpress plugin and i had a strange problem.
function aff_add_rewrite_rules( $wp_rewrite )
{
$new_rules = array(
'^redirect/([0-9]+)/$' => 'index.php?go=$matches[1]'); //question mark ? resolves the problem
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
The above rewrite rule
^redirect/([0-9]+)/$’ => ‘index.php?go=$matches[1]
simply refused to work, but it works for
^redirect/(.+)$’ => ‘index.php?go=$matches[1]
(.+) means anything including alphabets and numbers.
I only wanted the rewrite rule to accept numbers, not just anything and after researching a log, i found that the culprit was ? (question mark).
^redirect/?([0-9]+)/?$’ => ‘index.php?go=$matches[1]
and bingo! it worked! I never used the ? sign in htaccess rules and it appears to be wordpress needs it to parse the rewrite rules properly.
You can always refer to the list of wordpress 2.x rewrite rules while writing your custom rule.
Similar Posts:
- Where does wordpress store htaccess rewrite rules?
- Fixing WordPress custom permalinks 404 error
- Affiliate Hide v1.0 – Free WordPress plugin to Hide & Redirect Affiliate Links
- Disable Permalinks in WordPress folders
- Enabling ModRewrite in XAMPP Apache
- Affiliate Hide – Free wordpress plugin to redirect affiliate links!
- WordPress similar posts plugin not working?
- How to redirect when post submitted for review in WordPress
- 10+ Best Tutorials for WordPress Plugin Writing & Development
- Fix -> PHP files are downloading when viewed in Browser

