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?
- Affiliate Hide v1.0 – Free WordPress plugin to Hide & Redirect Affiliate Links
- WordPress similar posts plugin not working?
- Enabling ModRewrite in XAMPP Apache
- Affiliate Hide – Free wordpress plugin to redirect affiliate links!
- How to get custom field value in WordPress?
- How to manually upgrade wordpress from older versions
- Fix PNG transparency problem for IE6 in WordPress
- Fix -> PHP files are downloading when viewed in Browser
- [Fix] Fatal error: Unable to read 25447 bytes in index.php

