-I am using numerous WordPress rewrite rules to permit the injection of country-codes immediately at the outset of the URL path, which are utilized to determine a timezone offset. A good example:

add_rewrite_rule('^([A-Za-z]{2})/days/([0-9]+)/?$', 'index.php?geo=$matches[1]&m=$matches[2]&post_type=days','top');

This requires a request like www.daysoftheyear.com/days/2011/ (which may usually return all valid content with this request) and enables for, e.g., www.daysoftheyear.com/us/days/2011/ to come back exactly the same content however with support for any timezone offset in line with the country-code.

This works fine in just about all places, except for just one query type Body for 'days' custom publish type pages, e.g., http://www.daysoftheyear.com/days/waffle-day/.

The guidelines I've in position are:

add_rewrite_rule('^([A-Za-z]{2})/?$', 'index.php?geo=$matches[1]','top');
add_rewrite_rule('^([A-Za-z]{2})/days/([0-9]+)/?$', 'index.php?geo=$matches[1]&m=$matches[2]&post_type=days','top');
add_rewrite_rule('^([A-Za-z]{2})/days/([0-9]+)/([0-9]+)/?$', 'index.php?geo=$matches[1]&m=$matches[2]$matches[3]&post_type=days','top');   
add_rewrite_rule('^([A-Za-z]{2})/days/([0-9]+)/([0-9]+)/([0-9]+)/?$', 'index.php?geo=$matches[1]&m=$matches[2]$matches[3]$matches[4]&post_type=days','top');
add_rewrite_rule('^([A-Za-z]{2})/days/([A-Za-z\-].*)/?$', 'index.php?geo=$matches[1]&page=$matches[2]','top');
add_rewrite_rule('^([A-Za-z]{2})/([A-Za-z\-].*)/?$', 'index.php?geo=$matches[1]&pagename=$matches[2]','top');

The 5th rule shoud match http://www.daysoftheyear.com/gb/days/waffle-day/ in exactly the same as above, but redirects - I suspect it's confliucting using the built-in rules which make an effort to redirect to some correct URL whether it's malformed (e.g., basically type a detailed structural match to some correct URL, it'll redirect me towards the correct resource).

I'm able to make sure the 'raw' URL with this request works - e.g., http://www.daysoftheyear.com/index.php?geo=en&name=soup-month&post_type=days returns a legitimate and expected result.

I am not convinced this can be a regex rule, as opposed to a specific issue with the way in which Wordpress handles custom publish types?


Up-to-date to permit hyphens - no alternation in behavior, though regexpal reviews the regex works from the example URL.

Up-to-date after crippling Wordpress canonical redirects functionality - now 404'ing instead of 301'ing towards the page.

Up-to-date to make use of 'page' instead of 'pagename', in line with the information here: http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters - no alternation in behavior.

Up-to-date the code, added a linebreak and clarified that I am really referencing line 5, instead of line 4.

Resolved it seems the above ruleset now works properly - thanks all!

This request http://www.daysoftheyear.com/days/waffle-day/ will not suit your 4th rule because you did not allow - within the group cature : ([A-Za-z].*). Replace this group with ([A-Za-z\-].*) also it should match.