Two points:
-
Your rule isn’t particularly specific. For numeric matches you should be specific about it and specify a) digits and b) how many digits. Year would be
([0-9]{4})
, month/day would be([0-9]{1,2})
. -
You can’t do it with one rule. Add three separate rules instead.
add_rewrite_rule( 'whats-on/([0-9]{4})/?$', 'index.php?page_id=71&event_year=$matches[1]','top'); add_rewrite_rule( 'whats-on/([0-9]{4})/([0-9]{1,2})/?$', 'index.php?page_id=71&event_year=$matches[1]&event_month=$matches[2]','top'); add_rewrite_rule( 'whats-on/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$', 'index.php?page_id=71&event_year=$matches[1]&event_month=$matches[2]&event_day=$matches[3]','top');
Related Posts:
- Making extra parameters optional
- What add_rewrite_tag()’s RegEx matches against?
- add_rewrite_rule isnt working, not getting added to rules array, why?
- Why isn’t my rewrite rule working when there is no second parameter?
- WordPress add_rewrite_rule with 2 variables
- How to use endpoint, but remove/rewrite endpoint base?
- Regex in add_rewrite_tag not accepting OR operators?
- Querystring parameter getting lost in rewrite rule
- Custom post types and custom variables — add_rewrite_tag() question
- WordPress Custom URL Rewrites
- Does add_rewrite_rule(..) only accept “index.php” as redirect target?
- Cyrillic characters in rewrite rules cause 404 Not Found errors
- Custom Endpoint Gives 404 Header
- Clean URLs for custom $_GET variables
- WordPress URL rewrite regex
- why is are these rewrite_tags and rules not working?
- Redirect taxonomy to custom template to list terms in taxonomy
- How to change the matches in add_rewrite_rule
- resolve /author/ to a page or archive (of all authors) template
- Multiple values in a rewrite rule, is it possible?
- add_rewrite_rule() not working
- add_feed and flush_rewrite_rules
- Rewrite rules and query for virtual page
- Best action to call add_rewrite_rule
- Struggling with add_rewrite_rule
- add_rewrite_endpoint not working
- Associate the “add_rewrite_endpoint” and “$_GET”
- How to use rewrite rule or rewrite endpoint to switch languages?
- Add Rewrite Endpoint to CPT Archive
- Optional all capture groups in rewrite rule
- Does it still make sense using json endpoint ep_mask now that there’s the new rest api? [closed]
- Simple page URL rewrite with add_rewrite_rule()
- Custom rewrite_rules – only pass numbers and not alphabetic characters
- Optimal code for two add_rewrite_rule’s
- Custom URL rewrites work, but break my permalinks
- add_rewrite_rule – Additional subpages for author pages
- Rewrite custom post type URL parameters
- How do I flush rewrite rules
- rewrite url in wordpress
- My add_rewrite_rule is returning a 404
- Rewrite rule for path of favicon.ico ( Add_rewrite_rule function possible ? )
- wordpress add_rewrite_rule not working
- FLUSH_REWRITE_RULES – after or before REGISTER_POST_TYPE?
- Using get_query_var() from a plugin
- force_ssl_admin() causing issues with preview links
- $wp_rewrite->rules is always NULL
- WordPress CPT slug and page slug conflicts
- How can I reduce the number of rewrite rules?
- help with custom rewrite rules
- Order of rewrite rules when calling add_rewrite_rule
- Rewrite Rule for Post Meta
- add_rewrite_rule() not stored (I think)
- custom permalink for single post category
- WordPress add_rewrite_rule second argument not working
- WordPress rewrite does not work for some reason
- Rewrite rules ignored
- Adding a custom rewrite rule for gallery/categories page
- add_rewrite_rule issues
- Add_rewrite_rule doesn’t seem to work?
- add_rewrite_rule to search
- Rewrite rules applied differently after upgrade
- Leverage WP_Rewrite to pre-validate links / detect invalid links
- Is it possible to add a site-wide add_rewrite_rule for a multilingual site?
- WordPress rewrite rule doesn’t work unless post category is explicitly called in regex
- When request has multiple matching rewrite rules, and matched rule returns 404 – iterate to next rewrite rule
- WordPress – replicate same globals, query vars and query for an alternate endpoint
- Rewrite rule regex help required
- add_rewrite_rule not working for blog category page
- WordPress Own Rewrite Rules
- get_author_posts_url() doesn’t return the author URL, because of wrong author_structure
- rewrite rule not working: redirect to php script if file exists
- Homepage rewrite rule
- rewrite rules problem with #comments-2345
- How to add rewrite rule for product compare page?
- Rewrite post type into a page with year filter
- Why isn’t my rewrite rule for add_rewrite_rule not working as expected?
- WordPress matching URLs with trailing tildes code correction
- A part of regular expression in add_rewrite_rule function not working
- Flush rewrite rules when every page gives 500 error?
- Using add_rewrite_rule in conditional statement using $_SERVER
- Complex rewrite rules with multiple variables, some the same
- how to use mutliple add_rewrite_rule?
- Social sharing conflict with Rewrite rules
- Rewire Rules Front Page
- Rewrite permalink to include multiple taxonomies
- WordPress URL rewrite after changing web from Joomla
- Changing default slug of post to the post id
- How bad is flush_rules() on init hook?
- Where to hook to bypass instantiating WP_Query?
- Passing variables in the permalink structure on a custom post type
- WordPress Rewrite Rules
- add_rewrite_rule with trailing slash redirects
- nginx + W3 Total Cache: rewrite rules issue [closed]
- add_rewrite_rule() driving me crazy, rewrite not working when analyzer says it should
- Redirect to a file in a WordPress theme directory
- Direct domain alias to a specific WordPress page without the page in the URL
- rewriteRules WP6
- WordPress rewrite rule – not able to access second and third parameters
- Custom URL Rewrite Rules not working
- How to combine nearly identical custom rewrite rules for WordPress