Case-insensitive add_rewrite_rules in WordPress functions

As the answer below mentions, it is not possible to pass a flag to add_rewrite_rule(); however, it is possible to use an inline modifier. In your example, you would do this:

$aNewRules = array('(?i)my-books/?$' => 'index.php?pagename=my-books');

(note the (?i) in the regular expression).

The advantage of this approach is that your rewrite rules are much cleaner and more performant.

See this page on regular expression modifiers for more information.

Leave a Comment