This snippet should solve your problem. Just put it into your functions.php file.
function my_insert_rewrite_rules( $rules ) {
$newrules = array();
$newrules['search/([^/]+)/post_type/([^/]+)/?$'] = 'index.php?s=$matches[1]&post_type=$matches[2]';
return $newrules + $rules;
}
add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' );
function my_flush_rewrite_rules() {
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'my_flush_rewrite_rules' );
You will have to flush rewrite rules after adding this code, before it will start to work. Just switch theme to another and back or go to Settings->Permalink Settings and push “Save” button.
Related Posts:
- Unique URL Every Time
- Custom slug in front of search URL
- add_rewrite_rule not working for language specific characters
- Changing the search URL?
- Rewrite: WordPress URL rewrite on Search
- Force search form to go to clean url without multiple redirects
- WordPress search rewriting
- Change /search to /somethingelse
- Page not found: Custom search form with a custom search page
- WordPress how to prevent URL encoding in URL of taxonomy terms
- Changing the wordpress default search url to something like – …example.com/search?query=keyword
- How to change search page url so that it still returns a page when there’s no search query specified?
- Redirect empty search to another page
- How to add Search URL parameters to a Page Template Page for Custom Post Type
- Why is there a 404 on page 2+ for my search page?
- Rewrite URL for Search + Special Characters / Umlaute
- Change the search URL
- How to turn off searching from URL and go straight to 404 page
- How to make custom WordPress page deliver search results
- Rewrite Slug for CPT Archive Pages to Plural Name of Slug
- Change author base slug for different roles
- Custom Permalinks for Blog Posts Only
- Detect page type by url (Archive, single, page, author,…)
- Using a page template without a page
- How to seamlessly redirect between different archive and singular slugs?
- add_query_vars and add_rewrite_rules
- WordPress URLs without posts
- How to change ?lang=cn into /cn/
- Sub domain redirection to taxonomy
- custom htaccess rewrite rule for page
- Change URL for Blog?
- Sorting archive pages with “pretty” URLs?
- add_rewrite_rule again
- How to change page URLs to “www.site.com/page” instead of “example.com/blog/page” but keep post URLs as “example.com/blog/post”?
- Add_query_arg + two times the same argument?
- Redirecting all old links from previous EE site to new WP site in one go?
- Two “.htaccess” Files Located in Different Directories?
- Removing the post format (type) slug
- Redirect all posts urls from without .html to .html
- 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
- Custom user profile URLs
- Rewrite of URL with ‘[‘ ‘]’ or ‘(‘ ‘)’ as literals
- Define orderby in url
- Changing RSS feed URL structure
- Preserve Domain Alias
- Mobile version issue when domain forwarding with masking
- 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
- add_rewrite_rule is redirecting instead of rewriting url
- Rewrite rules automatically for pages using specific template
- Add language prefix to permalinks
- Custom Rewrite rule to captured post (rewrite rule to rewrite rule)
- Attachment page gives 404 if user not logged
- How to change the Author Slug from Username to Nickname and deal with Special Characters
- How to pass url as a parameter in a add_rewrite_rule
- Per Page Permalink Structure for Page Post Type
- Customise particular RSS permalink
- RSS feed rewrite matching wrong rule
- Removing “www” from a site URL
- Replace “http://localhost:8888/” by website URL in WordPress
- Custom rewrite rule not working
- Thousands of 404 errors on old posts due to embedded links
- WP Rewrite for a custom variable
- Creating a folder structure
- How to Detect That WP is Using Mod Rewrite or $_GET variables?
- How do I get posts to appear at mydomain.com/blog?
- rewrite rules and capturing
- Adding the amp url prefix to the beginning
- Custom taxonomy named ‘tag’ return 404 page
- Multiple permalink with and without category for same post
- Custom Params in URL
- Help adding custom url, rewrite_rules_array
- Implementing geotargeting while using a single database
- Url rewrite, add rule, redirect as POST request?
- Broken page redirect
- Add query arg for pretty permalinks in wordpress way
- Homepage cannot be found
- How to add 2 variable rewrite rule?
- Remove trailing slash
- Rewrite Url to a SEO-friendly format
- Use Parent Pages for URL Structure without Landing Page
- add_rewrite Rule
- How to show my application as referral in WordPress Stats
- Fully mask *all* traces of WordPress installation subdirectory?
- Appending parameters to WordPress query string in backend
- Redirect A URL Pattern In WordPress Using .htaccess
- Help to cleanup this code
- Rewrite Question
- How to make a custom route with any-string-part/number-part pointing to an existing page?
- username in rewritten URL, howto use it in a template
- Rewwrite rule for mapping plugin static file
- Listing Authors – URL Formats [duplicate]
- wordpress url rewrite Query Var to Static url
- Add rewrite endpoint and .htaccess
- Remove url parameter using wordpress
- Rewrite rule to simulate page hierarchy results in 404
- add_rewrite_rule not working with custom variables