Your regular expression is requiring the last slash be present which it will not be by default. So the path tides/mylocation/
is shortened to tides/mylocation
and then tested. Instead, wrap the last part in an optional group using the ?
and update the match number.
add_rewrite_rule('tides/([^/]+)(/([^/]+))?', 'index.php?page_id=4348&location=$matches[1]&month=$matches[3]', 'top');
Related Posts:
- What add_rewrite_tag()’s RegEx matches against?
- Regex in add_rewrite_tag not accepting OR operators?
- Prettified page URL w/ query var redirects to prettified page URL w/o query var
- Making extra parameters optional
- why is are these rewrite_tags and rules not working?
- Redirect taxonomy to custom template to list terms in taxonomy
- Multiple values in a rewrite rule, is it possible?
- add_rewrite_rule isnt working, not getting added to rules array, why?
- add_rewrite_endpoint not working
- Making extra parameters optional
- WordPress add_rewrite_rule with 2 variables
- Passing variables in the permalink structure on a custom post type
- When should add_rewrite_tag() be used?
- Why does everybody hook add_rewrite_rule on init
- add_rewrite_rule() vs $wp_rewrite->rules vs ‘rewrite_rules_array’?
- How to check if a rewrite rule exists
- Querystring parameter getting lost in rewrite rule
- Rewrite Rules for Multiple (more than 2) Taxonomies
- Custom post types and custom variables — add_rewrite_tag() question
- add_rewrite_rule not producing anything in $_GET
- Flush_rewrite_rules not working when settings updated
- WordPress Custom URL Rewrites
- Case-insensitive add_rewrite_rules in WordPress functions
- 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
- flush_rewrite_rules() cancels the effect of add_rewrite_rule()
- Separate posts by chapter per rewrite
- How to change the matches in add_rewrite_rule
- Using add_rewrite_rule() to redirect to Front Page
- resolve /author/ to a page or archive (of all authors) template
- add_rewrite_rule() not working
- Permalinks, Rewrites, Get Variables, Oh My!
- add_feed and flush_rewrite_rules
- Rewrite rules and query for virtual page
- add_rewrite_rule parameter is not received by the page
- add_rewrite_rules prefix everything
- Can someone explain the function of the third parameter of “add_rewrite_tag”
- custom permalink/shortlink with base62 encoded post ID
- Best action to call add_rewrite_rule
- Struggling with add_rewrite_rule
- How to restore WP 5.4 behaviour where a numeric string could added to each page URL and parsed as “page” in WP 5.5?
- get_query_var with add_rewrite_rule and add_filter(‘query_vars’) not working
- Can rewrites fallback if 404? Rewrite conflict issue
- Reading Settings -> Front Page displays “Static Page” being reset
- add_rewrite_rule query_var not being set
- How to properly rewrite url by custom var
- why does add_rewrite_rule refresh and loose url variables
- Where do I USE add_rewrite_rule?
- add_rewrite_rule confusion
- Custom query_vars and parse_request on wp-admin
- Associate the “add_rewrite_endpoint” and “$_GET”
- Custom Rewrite rule to match anything not already matched by WordPress
- Uppercase to Lowercase in URL
- How to use rewrite rule or rewrite endpoint to switch languages?
- How to add custom variable in url without redirect?
- Rewrite rule to prettify two $_GET variables while in a new endpoint from a page
- Remove rewrite endpoint on deactivation?
- Do I need to flush rewrite rules when creating new user if using custom author rewrite rules?
- Add Rewrite Endpoint to CPT Archive
- Optional all capture groups in rewrite rule
- Rewrite rule : custom post type with 2 numeric variiables
- 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
- Hooking “delete_option_rewrite_rules” for rewrite rule addition
- Optimal code for two add_rewrite_rule’s
- Custom URL rewrites work, but break my permalinks
- WordPress shows front page, when it should show 404 with pagination style urls
- add_rewrite_rule – Additional subpages for author pages
- Displaying Post with Custom URL with RewriteRule or add_rewrite_rule
- Can’t get custom rewrite tag, query var, permastruct (permalink structure), and rewrite rule to work properly together
- Rewrite URLs – Custom Post Type – Post Slug, Taxonamy Slug
- Rewrite rule problem
- How do I flush rewrite rules
- add_rewrite_rule redirects if value = 1
- Pass query vars to front page
- Rewrite query string to path
- rewrite url in wordpress
- Custom permalink leads to index page
- add_rewrite_rule permalinks break in WordPress 4.5
- How to add rewrite rule for external php file
- Help with rewrite rules for two post types
- Enpoint Not Found in Rewrite Tag Permalink
- 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
- How to flush rewrite rules on the activation of any plugin
- force_ssl_admin() causing issues with preview links
- How to test custom rewrite rules /permalinks?
- $wp_rewrite->rules is always NULL
- Rewrite without query parameter
- WordPress CPT slug and page slug conflicts
- How can I reduce the number of rewrite rules?
- Mod_rewritte – remove ?m=1 from url
- Rewrite Rules problem when rule includes homepage slug