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’?
- add_rewrite_rule not producing anything in $_GET
- Flush_rewrite_rules not working when settings updated
- Case-insensitive add_rewrite_rules in WordPress functions
- 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
- add_rewrite_rule() not working
- 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”
- 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?
- 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
- 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?
- Hooking “delete_option_rewrite_rules” for rewrite rule addition
- WordPress shows front page, when it should show 404 with pagination style urls
- Displaying Post with Custom URL with RewriteRule or add_rewrite_rule
- Rewrite URLs – Custom Post Type – Post Slug, Taxonamy Slug
- add_rewrite_rule redirects if value = 1
- Rewrite query string to path
- 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
- How to flush rewrite rules on the activation of any plugin
- How to test custom rewrite rules /permalinks?
- Rewrite without query parameter
- Rewrite Rules problem when rule includes homepage slug
- WooCommerce – Conditional for page created by rewrite_rule
- add_rewrite_rule() not stored (I think)
- flush_rewrite_rules() not working on updating Settings API
- Rewrite rules for short URL
- How do I turn off the blog and archives?
- Adding a custom rewrite rule for gallery/categories page
- How to do make mysite.com/post-name/sub-post?
- Custom rewrite rules for a page with GET variables?
- WordPress add a rewrite rule to a page to accept a GET variable
- “/” URLs without trailing slash shows 404
- How can I resolve search error with pagination wordpress
- wordpress path generation from rewrite rule
- CPT – Nice url with add_rewrite_rule
- Multiple Taxonomy Items for Separate URLs
- add_rewrite_rule only works when flush first
- Rewrite rule not working, issue may be in URI request
- custom rewrite rules will not be added to wordpress rewrite_rules database
- Overcoming a complex WordPress page rewrite rules request
- How to create a custom URL to another domain in WordPress
- Custom Fields Query Vars and Rewrite not working
- Rewrite Rules, Query Vars and Pagination
- Pretty links with add_rewrite_rule and add_query_var
- Create new URL structure for custom post types
- How to change URL in WordPress
- WordPress Rewrite rule with custom query var
- default ‘post’ post type: not forcing url rewrite when args set
- How to add rewrite rule to point to file
- Last query_var not working with rewritten URL
- add_rewrite_rule doesn’t work for me
- Rewritten URL not loading WordPress environment
- WordPress Custom post type single page 404 error
- Custom Rewrite Tag Structure
- Rewrite for page with a possible unknown parent page
- Rewrite the WordPress URL from custom plugin
- add_rewrite_rule works only with one “directory”
- URL Rewrite for CPT single posts
- Rewrite Rule & Regex – Extract ‘cat-name’ and ‘page-number’ from http://domain.com/custom-post-type/category/cat-name/page/page-number
- Rewrite rule help for gallery plugin
- How to Add Rewrite Ruled Argument Into Permalink Properly
- Overwrite WP’s default search rule to redirect to my own template
- add_rewrite_rule not working with custom post type
- Custom URL rewrite with add_rewrite_rule
- Rewrite rule to index.php in theme subfolder
- wordpress category rewrite rule with pagination
- make a new structure tag that does some processing