In your rewrite rule, pagename
should in fact be the query_var
of your custom post type. Unless you used query_var => 'something_else'
in your register_post_type
arguments, it’ll be the same name as your custom post type:
index.php?locations=$matches[2]
Related Posts:
- add_rewrite_rule: $matches var not replaced by captured value
- How to change default page slug?
- Custom rewrite rule
- Redirect empty search to another page
- Remove part from dynamic url and redirect
- Broken page redirect
- Migration from old CMS to WordPress 301 redirection rules?
- Dynamic Endpoints
- How to add custom rewrite rule to .htaccess?
- Problem with add_rewrite_rule and pagination (paged and page query_vars)
- Rewrite url for custom post type
- add_query_vars and add_rewrite_rules
- Need help with rewrite_rules_array
- Mod_rewrite delete parameter in 301 Redirect
- add_rewrite_rule not working for page var
- Custom rewrite rules are sending everything to index.php
- Sub domain redirection to taxonomy
- WordPress Network on IIS7/SQL Server – Rewrite Issues
- Custom comments
- flush_rewrite_rules not working on plugin deactivation, invalid URLs not showing 404
- add_rewrite_rule again
- Redirecting all old links from previous EE site to new WP site in one go?
- Add rewrite rule to call front-page.php?
- Evaluating a external rewrite rule before internal wordpress rewrite rule
- Rewriting rules: difference between ‘init’, ‘rewrite_rules_array’, ‘generate_rewrite_rules’?
- WordPress rewrite rules for state and city
- Multiple Permalinks for Same Post
- Single Redirection Rule for Pages and Archive links
- Home page with Polylang redirects to other page [closed]
- expecting 404 but redirecting to post with url subdirectory in post title
- Remove “/page/1” from the URL
- hard flush_rewrite_rules() not regenerating .htaccess
- Remove Query String from URL on Redirect – Redirection Plugin
- add_rewrite_rule() to route to file other than index.php
- Rewrite Rules Are Redirecting and Not Passing VARs
- WordPress rewrite rules don’t need ^?
- custom template rewrite
- add_rewrite_rule fro html to another url not working
- WordPress redirects non-existing url to existing ones – how to disable
- How to building pretty URLs to reflect category hierarchy?
- WordPress Rewrites – How can I pass a variable to Custom Post Type?
- Need to add rewrite rule that adds in additional information about the post to url
- Can I change default registration link (without htaccess)?
- How do I display only the parent page in the url
- add_rewrite_rule is redirecting instead of rewriting url
- Rewrite rules automatically for pages using specific template
- Custom Rewrite rule to captured post (rewrite rule to rewrite rule)
- Rewrite the default post object’s permalink
- QSA Rewrite Rule
- How to pass url as a parameter in a add_rewrite_rule
- Per Page Permalink Structure for Page Post Type
- Customise particular RSS permalink
- ReWrite rule for files of a previously standalone blog moved to network
- RSS feed rewrite matching wrong rule
- Best way to trigger rewrite rules
- Trouble with question mark in rewrite rule
- Redirect htaccess [closed]
- What URL rewriting rule should I write to retrieve a var in the URL?
- Custom rewrite rule not working
- rewriterule not working
- Redirect URL to an existing page with query string or #! added on
- How do I make WordPress revise an .htaccess file a certain way?
- How can I allow trailing slashes on some URLs without a redirect, but not on others?
- Can’t use a specific custom URL (slug)?
- How are rewrite rules applied in WordPress?
- How to change an existing wordpress page rewrite rule?
- URL rewriting in wordpress using parameters
- Adding the amp url prefix to the beginning
- Redirect to new domain that serves new and different content
- Rewrite rules – page does not exist
- Redirect users with “.” (dot) in their username and replace with “-” (dash) to correct profile
- Rewrite Rules are Redirecting
- How to redirect to a login virtual page?
- Issue with custom rewrite for products and permalinks
- Prefix only some posts with a custom prefix
- Help adding custom url, rewrite_rules_array
- How to use a capture from a rewrite rule inside a php file (like single.php)?
- url rewriting on custom post type
- Rewrite rule not redirecting correctly
- Remove trailing slash
- add_rewrite Rule
- rewrite rule of post when accessed from archives pages
- How to create short urls for sharing and downloadable content?
- Font Page overrides rewrites
- Redirect A URL Pattern In WordPress Using .htaccess
- Rewrite rule is not working
- How to make a custom route with any-string-part/number-part pointing to an existing page?
- rewrite rule for home/index page
- Post Type Rewrite Custom
- Rename page URL
- Changes done to .htaccess are not getting reverted back
- Help with url rewrite
- How to change search url produced by ‘s GET method?
- Programmatically add a custom url route “/category/index.json” to return a collection of posts in json
- Rewrite URLs in a Custom Post Type with Multiple Taxonomies
- Rewrite rule giving 404 error
- Using .htaccess to redirect /da/ to / in URL
- WordPress picks a wrong template if ?cat= is used as URL parameter
- WP-Include rewrite directory
- How to combine nearly identical custom rewrite rules for WordPress