The first rule is capturing all requests. If you add a $
anchor at the end of the rules, they’ll behave as expected (you could also just switch the order of the rules so the more specific one “wins”).
add_rewrite_rule(
'^app/course/([^/]+)/?$',
'index.php?page_id=3400&course=matches[1]',
'top'
);
add_rewrite_rule(
'^app/course/([^/]+)/theme/([^/]+)/?$',
'index.php?page_id=3400&course=$matches[1]&theme=$matches[2]',
'top'
);
Check out Monkeyman Rewrite Analyzer for debugging rules.
Also note that theme
is used by WordPress internally as a POST or GET var, I suggest changing that to something unique to prevent any potential conflict.
Related Posts:
- Rewrite Rules for Multiple (more than 2) Taxonomies
- Custom query_vars and parse_request on wp-admin
- How to add custom variable in url without redirect?
- Rewrite URLs – Custom Post Type – Post Slug, Taxonamy Slug
- Enpoint Not Found in Rewrite Tag Permalink
- Get wordpress installation folder
- WordPress Rewrite rule is not working
- How to change an existing wordpress page rewrite rule?
- wordpress path generation from rewrite rule
- add_rewrite_rule() issue with parent/child/child page
- URL Rewrite for CPT single posts
- help with rewrite_tag and rewrite_rule for custom page GET variables [duplicate]
- Rewrite URLs in a Custom Post Type with Multiple Taxonomies
- add_rewrite_rule doesn’t work when trying to add a new parameter at the end of URL
- How do you create a “virtual” page in WordPress
- Rewrite rules not working in WordPress
- How to add custom rewrite rule to .htaccess?
- Problem with add_rewrite_rule and pagination (paged and page query_vars)
- Preserving $_GET parameter while using custom Rewrite Rule
- Taxonomy rewrite question
- Why does wordpress still strip my query var?
- When to call `add_rewrite_rule` for safety
- Getting add_rewrite_rule and add_rewrite_tag to work
- Rewrite rules goes away
- Rewrite Rule for Custom Page with Query Vars in URL
- Dynamic URL, not a physical page within the database
- Rewrite Rule for Post “Subpage”, with pagination
- Need to make a php file inside theme accessible via url
- WP Rewrite the last two parts of the URL
- Rewrite loading custom template file but is_home() returns true, and there’s no 404
- Rewrite rule for admin-ajax.php
- Nginx rewrite rule conflict with WordPress permalinks rule
- Access $_POST data after redirect
- Change Query String to pretty permalink
- add_rewrite_rule not working for language specific characters
- How to add a custom redirect rule for subdomains?
- How to do Basic URL Rewrite Without Redirecting
- Is it possible to remove feeds from rewrites?
- URL Rewrite doesn’t work for nested pages
- Flush Rewrite Rules on init or rest_api_init?
- Rewrite URL – insert custom variables as a directory path
- How to properly rewrite url by custom var
- Can’t add external rewrites
- url rewrite parsing a custom url parameter not working
- Using category slug in add_rewrite rule
- add_rewrite_rule ignoring other params than the “p” param
- Url Rewriting a dynamic wordpress page
- How to catch Rewrite rules then display a specific post?
- Adding two rewrite rules
- Load an url with minimal/no DB queries
- .htaccess rewrite
- Auto generate rewrite rules for multiple taxonomies
- Help with Rewrite Rule for Custom Post Type with Query String
- URL Rewriting for PHP script on an image URL
- Create Dynamic SEO Friendly URL for Virtual Page
- add_rewrite_rule with query variables
- Rewriting “pretty” blog category URL with htaccess / add_rewrite_rule() causes 404 page
- Rewrite query string to path
- Custom permalink leads to index page
- Rewrite API -Adding a parameter before the slug
- How to pass url as a parameter in a add_rewrite_rule
- Per Page Permalink Structure for Page Post Type
- Customise particular RSS permalink
- RSS feed rewrite matching wrong rule
- Rewrites rules disappear after a while
- Adding a rewrite rule to page that has no fixed variables and pagination
- Flush rewrite rules on option update with Settings API
- Localize URL bases
- Combine multiple CPT names to create valid permalinks
- Rewrite specific action url
- Using URL rewrite to add custom URL for custom post type
- WordPress simple Url Rewrite
- Custom rewrite rule not working
- Rewriting in wordpress url
- Why is a rewrite rule in wordpress prevent pagination?
- Rewrite custom taxonomy slug – but only parent items
- How can I allow trailing slashes on some URLs without a redirect, but not on others?
- Can’t use a specific custom URL (slug)?
- Adding the amp url prefix to the beginning
- Multiple Taxonomy Items for Separate URLs
- Rewrite WordPress Url from root to subfolder without moving files
- How to redirect to a login virtual page?
- Ugly URLs when there’s pagination
- How do I rewrite URL that has custom parameter
- Help adding custom url, rewrite_rules_array
- Why is there a 404 on page 2+ for my search page?
- Rewrite rule for post as a child of a CPT
- Broken page redirect
- URL Rewrite and Archive Template Files – Post Type vs. Taxonomy
- add_rewrite Rule
- rewrite rule of post when accessed from archives pages
- .htaccess RewriteBase equivalent for WordPress – Passing a URL as a variable without getting a 404
- Migration from old CMS to WordPress 301 redirection rules?
- Using add_rewrite_tag to create urls for page sections
- Rewriting WordPress URLs
- Can’t get pretty permalinks to work without index.php
- Wrong rewrite rules
- Rewrite and replace url wp-admin/edit.php and wp-admin/post-new.php
- Programmatically add a custom url route “/category/index.json” to return a collection of posts in json
- WP-Include rewrite directory