I have these slugs on my website
http://www.domain.com/about (standard WP page)
http://www.domain.com/custom-slug (not a WP page, post or custom post type)
I'm trying to develop a rewrite rule to match the latter scenario, to redirect them to my custom plugin so I can render content for them. My rewrite rule looks like this
add_rewrite_rule('^(.*)/?', 'index.php?pagename=special-page&id=$matches[1]', 'bottom');
By setting it to 'bottom'
it kicks in after all other WordPress rewrite rules, and so won't get processed - WordPress will send a request for /custom-slug
to the 404 page.
If I set the rewrite rule to 'top'
then every page on WordPress will be matched. That would be ok if my rewrite rule executed and it checked in a custom database table to see if /custom-slug
is a valid slug in my custom system. If it does then render content for it. If it doesn't to have WordPress continue on trying to make a match for it (redirect /about
to the actual about page on the site)
Normally rewrite rules are more straightforward where you match a specific keyword in the URL following by a string after it, but that won't work for me - all slugs will look the same.
Any ideas on how best to accomplish this?