Your external rule doesn’t work because you’re using a format that only works for internal rules- $matches[1]
is essentially nonsense in the context of an .htaccess file. Using the $matches
array will only work when rules are parsed by PHP, external rules need to use the standard $1
instead of $matches[1]
. Any rule that doesn’t point to index.php
is interpreted as an external rule and gets added to .htaccess instead of the internal rules array.
That said, I suggest changing things a bit and adding a rewrite endpoint instead of a rule. Your URLs would be:
You could then check if get_query_var('ajax')
is set in your templates.
Related Posts:
- Clean URLs for custom $_GET variables
- WordPress rewrite does not work for some reason
- How to create custom URL routes?
- remove “index.php” from permalinks
- 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
- 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
- How to change default page slug?
- WordPress Custom URL Rewrites
- Case-insensitive add_rewrite_rules in WordPress functions
- Mod_rewrite delete parameter in 301 Redirect
- 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
- Prettified page URL w/ query var redirects to prettified page URL w/o query var
- Need to make a php file inside theme accessible via url
- Making extra parameters optional
- Can I write ‘RewriteCond’ using ‘functions.php’?
- flush_rewrite_rules() cancels the effect of add_rewrite_rule()
- why is are these rewrite_tags and rules not working?
- Separate posts by chapter per rewrite
- Redirect taxonomy to custom template to list terms in taxonomy
- 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
- Cache Busting using htaccess Rewrite rule?
- Multiple values in a rewrite rule, is it possible?
- What add_rewrite_tag()’s RegEx matches against?
- Evaluating a external rewrite rule before internal wordpress rewrite rule
- add_rewrite_rule() not working
- 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”
- Best action to call add_rewrite_rule
- 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
- why does add_rewrite_rule refresh and loose url variables
- Where do I USE add_rewrite_rule?
- Rewrite rule to load images from production does nothing
- add_rewrite_rule confusion
- add_rewrite_rule isnt working, not getting added to rules array, why?
- add_rewrite_endpoint not working
- Rewrite Rules Are Redirecting and Not Passing VARs
- WordPress rewrite rules don’t need ^?
- 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?
- Remove rewrite endpoint on deactivation?
- Do I need to flush rewrite rules when creating new user if using custom author rewrite rules?
- How can i redirect one url to another url using .htaccess or add_rewrite_rule
- Add Rewrite Endpoint to CPT Archive
- Custom rewrite not working
- 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()
- Hooking “delete_option_rewrite_rules” for rewrite rule addition
- WP is ignoring .htaccess rewritten URL
- ReWriteRules and WordPress Multi-Sites with Sub Directories
- Optimal code for two add_rewrite_rule’s
- Rewrite wp-login.php URLS to static pages?
- 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
- Rewrite custom post type URL parameters
- .htaccess rules for blocking bots with an extra condition
- Displaying Post with Custom URL with RewriteRule or add_rewrite_rule
- Rewrite URLs – Custom Post Type – Post Slug, Taxonamy Slug
- URL Rewriting for PHP script on an image URL
- Rewrite rule problem
- Change pagination url format
- How to remove specific category from URL in WordPress
- Redirections and rewrites to subdomain
- How do I flush rewrite rules
- add_rewrite_rule redirects if value = 1
- Rewriting “pretty” blog category URL with htaccess / add_rewrite_rule() causes 404 page
- Pass query vars to front page
- Rewrite Rules and Login Issue
- Custom Rewrite rule to captured post (rewrite rule to rewrite rule)
- Taxonomy Pagination Rewrite
- rewrite url in wordpress
- Image URLs not redirecting properly
- add_rewrite_rule permalinks break in WordPress 4.5
- How to add rewrite rule for external php file
- Making extra parameters optional
- My add_rewrite_rule is returning a 404
- URL rewriting with custom user meta “/%shop_name%/gallery/%gallery%”
- 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?