I’m trying to add a new external/non-WP rewrite rule to my .htaccess but WP keeps adding [QSA,L] to the end of the rule.
How do I prevent the QSA part?

This line adds the RewriteRule:

$wp_rewrite->add_external_rule('go/([0-9]+)/?.*$', 'wp-content/plugins/xswpc/redirect.php?id=$1');

And this is the resulting line in my .htaccess

RewriteRule ^go/([0-9]+)/?.*$ /wp-content/plugins/xswpc/redirect.php?id=$1 [QSA,L]

What I’d like is:

RewriteRule ^go/([0-9]+)/?.*$ /wp-content/plugins/xswpc/redirect.php?id=$1 [L]

2 Answers
2

The apache rewrite flags like QSA are hard coded, see source. Not sure why it would bother you, but if you really want to change it, then you can and should use the mod_rewrite_rules hook for that. Below an example on how to do it:

add_filter( 'mod_rewrite_rules', 'wpse107528_change_mod_rewrite_rules' );
function wpse107528_change_mod_rewrite_rules( $rules ) {
    $pattern = '/^(?<=RewriteRule\s\^go.+\$1\s)(\[QSA,L\])$/im';
    $replacement="[L]";
    $rules = preg_replace( $pattern, $replacement, $rules );
    return $rules;
}

Beware I haven’t tested the Regex.

Leave a Reply

Your email address will not be published. Required fields are marked *