Figured out a solution! This intercepts the query at parse_request
, checks if a page with a matching slug exists, and if so, changes the request to a page request.
/**
* Fix rewrite conflicts between "project_category" and "page"
*
* @param WP $query
* @return WP
*/
function prefix_parse_request_fix_rewrite_conflicts_project_category(WP $query): WP {
if (isset($query->query_vars["project_category"])) {
$path = preg_replace("/\//", "", $_SERVER["REQUEST_URI"]);
if (get_page_by_path($path, OBJECT, "page")) {
unset($query->query_vars["project_category"]);
$query->query_vars["pagename"] = $path;
}
}
return $query;
}
add_action("parse_request", "prefix_parse_request_fix_rewrite_conflicts_project_category");
Related Posts:
- How to create custom URL routes?
- How to change default page slug?
- Mod_rewrite delete parameter in 301 Redirect
- Need to make a php file inside theme accessible via url
- Evaluating a external rewrite rule before internal wordpress rewrite rule
- Rewrite rule to load images from production does nothing
- Rewrite Rules Are Redirecting and Not Passing VARs
- WordPress rewrite rules don’t need ^?
- Custom rewrite not working
- WP is ignoring .htaccess rewritten URL
- Rewrite wp-login.php URLS to static pages?
- Rewrite custom post type URL parameters
- Rewrite URLs – Custom Post Type – Post Slug, Taxonamy Slug
- URL Rewriting for PHP script on an image URL
- Change pagination url format
- Rewriting “pretty” blog category URL with htaccess / add_rewrite_rule() causes 404 page
- Custom Rewrite rule to captured post (rewrite rule to rewrite rule)
- URL rewriting with custom user meta “/%shop_name%/gallery/%gallery%”
- Localize URL bases
- How can I create custom URL routes?
- How do I make WordPress revise an .htaccess file a certain way?
- How to change an existing wordpress page rewrite rule?
- Pretty URL via Rewrite
- Custom Rewrite for Profiles
- help with rewrite_tag and rewrite_rule for custom page GET variables [duplicate]
- Can’t get pretty permalinks to work without index.php
- Change the “page” slug in pagination
- Understanding add_rewrite_rule
- generate_rewrite_rules (action) vs add_rewrite_rule (function): which one is preferred?
- Rewrite Rules for Multiple (more than 2) Taxonomies
- add_rewrite_rule not loading correct page nor getting variables
- SEO Friendly URLs for my plugin categories
- How do I add a add_rewrite_rule without it redirecting?
- WordPress URL rewrite regex
- Getting add_rewrite_rule and add_rewrite_tag to work
- Blog installed in subdirectory but need to create pages in root. How to use permalinks?
- WordPress keeps writing rewrite rules to .htaccess
- WordPress Rewrite
- Custom rewrite rule for backend/admin?
- How to have multiple rewrite endpoints in the same URL?
- add_rewrite_rule is not taking effect in WordPress? .htaccess file doesn’t update
- Regionalised Content
- Add specific word to default page permalink
- Plugin action rewrite rule – non_wp_rules
- Map alt domain to specific section of website w/o MU
- Custom query_vars and parse_request on wp-admin
- Have two different URLs show the homepage
- My WP_options db rewrite_rules Does Not Work
- Custom rewrite_rules – only pass numbers and not alphabetic characters
- a one-off rewrite rule
- Rewrite ugly URL to clean URL
- How to remove wordpress directory slash
- Changed pagination URLS to use p= instead of paged=
- Rewrite: WordPress URL rewrite on Search
- WPML language switcher for custom rewrite rules
- How to write Rewrite rule for same path using Rewrite API?
- URL Rewrite and add_query_var not working
- How to add custom rewrite rules and point to specific templates
- Custom rewrite after the default term link URL
- How can I reduce the number of rewrite rules?
- Capturing /page-name/[0-99999] in both template and number
- custom wordpress rewrite
- Keep requested/entered url with add_rewrite_rule
- Get wordpress installation folder
- Name page template properly
- Rewrite Rule for homepage not working correctly
- One off rewrite for single post-type slug (show normal page with same URL instead)
- Adding Rewrite URL for Base + Children Separately
- WP redirect rule doesn’t work
- Rewriting a date hierarchy into a ‘yyyy-mm-dd’ slug
- URL rewrite in theme doesn’t seem to be working
- Why wp redirects me to wp-login.php when I visit a rewritten wp-admin URL?
- modify URL with mod_rewrite or hook
- Rewrite rules for custom post type
- Rewrite rule that wp-login.php?action=register is left alone
- Trying to add array of paths to post permalink
- How to rewrite URL back to default custom URL if no destination found
- Dynamic URL with rewrite rule not working
- How can I add a vanity URL for admin-ajax.php Calls?
- Remove part from dynamic url and redirect
- How to get relative page for every post: /post-1/contact. /post-2/contact
- Rewrite rule can’t get the ID from rewrited
- WordPress Rewrite Rule to EITHER Match 1 or 2 Taxonomies when adding to URL
- WordPress numeric (yearly) page names / disable yearly archives
- Rewrite Rule added but showing 404 rather than specified page
- Blog List Page 404 With Custom Post Type Rewriting to Blog Parent
- ModRewrite not working properly
- Need help with custom rewrite rule
- WordPress doesn’t remember my custom rewrite rule
- Custom urls in WordPress involving page slugs
- how to change some of the rules in the database
- rewrite rules social share links
- Rewriting URLs with query strings and preserving them
- add_rewrite_rule is not fired
- Custom URL scheme – paramters on custom post type
- get_permalink is getting old rewrite rule
- WordPress Custom Rewrite Rule
- Rewrite function
- Please give me the rewrite rules for my ugly urls
- Wrong rewrite rules