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
- 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
- add_rewrite_rule not producing anything in $_GET
- Flush_rewrite_rules not working when settings updated
- How to change default page slug?
- Case-insensitive add_rewrite_rules in WordPress functions
- 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
- flush_rewrite_rules() cancels the effect of add_rewrite_rule()
- 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
- Evaluating a external rewrite rule before internal wordpress rewrite rule
- 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”
- 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?
- add_rewrite_rule confusion
- 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
- Hooking “delete_option_rewrite_rules” for rewrite rule addition
- ReWriteRules and WordPress Multi-Sites with Sub Directories
- 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
- URL Rewriting for PHP script on an image URL
- Rewrite rule problem
- How to remove specific category from URL in WordPress
- add_rewrite_rule redirects if value = 1
- Rewriting “pretty” blog category URL with htaccess / add_rewrite_rule() causes 404 page
- Custom Rewrite rule to captured post (rewrite rule to rewrite rule)
- Taxonomy Pagination Rewrite
- add_rewrite_rule permalinks break in WordPress 4.5
- How to add rewrite rule for external php file
- How to flush rewrite rules on the activation of any plugin
- Rewrite without query parameter
- Localize URL bases
- Rewrite Rules problem when rule includes homepage slug
- add_rewrite_rule() not stored (I think)
- How can I create custom URL routes?
- flush_rewrite_rules() not working on updating Settings API
- Rewrite rules priority
- Rewrite rules for short URL
- How do I turn off the blog and archives?
- Adding a custom rewrite rule for gallery/categories page
- Grab last part of the url inside rule
- Why isn’t my rewrite rule working when there is no second parameter?
- 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
- How can I resolve search error with pagination wordpress
- CPT – Nice url with add_rewrite_rule
- WordPress – replicate same globals, query vars and query for an alternate endpoint
- WordPress add_rewrite_rule with 2 variables
- Rewrite rule not working, issue may be in URI request
- Rewrite post type into a page with year filter
- How to create a custom URL to another domain in WordPress
- Rewrite Rules, Query Vars and Pagination
- Pretty links with add_rewrite_rule and add_query_var
- Flush rewrite rules when every page gives 500 error?
- How to change URL in WordPress
- WordPress Rewrite rule with custom query var
- Cannot get 301 redirection in htaccess to work (either Redirect or Rewrite)
- default ‘post’ post type: not forcing url rewrite when args set
- How to add rewrite rule to point to file
- Template hierarchy changes when custom post-type permalink leverages custom taxonomy
- Last query_var not working with rewritten URL
- Adding custom slugs: parent-page/username/child-page/
- Rewritten URL not loading WordPress environment
- WordPress Custom post type single page 404 error
- Rewrite for page with a possible unknown parent page
- Rewrite the WordPress URL from custom plugin
- add_rewrite_rule works only with one “directory”
- Passing variables in the permalink structure on a custom post type
- how to exclude admin page from add_rewrite_rule in wordpress
- Only homepage working correctly, 404 error on everything else
- WordPress Rewrite Rules
- help with rewrite_tag and rewrite_rule for custom page GET variables [duplicate]
- Can’t get pretty permalinks to work without index.php
- URL Redirect on GoDaddy platform [closed]
- Custom URL rewrite with add_rewrite_rule
- Rewrite rule to index.php in theme subfolder
- Direct domain alias to a specific WordPress page without the page in the URL
- WordPress rewrite rule – not able to access second and third parameters
- Custom URL Rewrite Rules not working