The WordPress Rewrite API is a solid API assuming that you’re comfortable with regular expressions.
And, honestly, even if you’re not, tools like PHP Live RegEx make it really easy to test your code before dropping it into the add_rewrite_rule
API call.
However, there are times where you may find yourself in a situation in which you need to work with rewrite rules and page templates. And when that’s the case, it’s not always as straightforward as making a simple call with a single regular expression.
The reason? If you have multiple pages using the same template, then you’re not always going to have the page located in the same index in the query that runs on each page.
To that end, we to have to handle it in a slightly different way than, say, simply accessing a numerical index of information in the global query.